[sword-svn] r83 - trunk/src/installer
bdrake at www.crosswire.org
bdrake at www.crosswire.org
Wed Jan 2 11:14:33 MST 2008
Author: bdrake
Date: 2008-01-02 11:14:32 -0700 (Wed, 02 Jan 2008)
New Revision: 83
Modified:
trunk/src/installer/doInstall.cpp
Log:
Fully working version. Added delete of modules. Will now install and delete any module directly on mobile device.
Modified: trunk/src/installer/doInstall.cpp
===================================================================
--- trunk/src/installer/doInstall.cpp 2008-01-01 17:23:30 UTC (rev 82)
+++ trunk/src/installer/doInstall.cpp 2008-01-02 18:14:32 UTC (rev 83)
@@ -62,7 +62,7 @@
if (INVALID_HANDLE_VALUE == hDest) {
MessageBox::Show("Sorry, I can't seem to write files to your PC.\
Do you have a mods.d directory where you put me?", "Process Failed",
- MessageBoxButtons::OK);
+ MessageBoxButtons::OK); // TODO - line break in MessageBox???
Application::Exit();
}
if (CeReadFile(hSrc, &Buffer, sizeof(Buffer), &dwNumRead, NULL)) {
@@ -96,6 +96,7 @@
wcscat_s(searchPath, L"*");
if(!CeFindAllFiles(searchPath, FAF_ATTRIBUTES | FAF_NAME, &foundCount, &findDataArray)) {
_tprintf( TEXT("*** CeFindAllFiles failed. ***\n"));
+ // TODO - replace above with MessageBox
return(NULL);
}
if(!foundCount) return(NULL);
@@ -255,8 +256,8 @@
}
if(!foundCount) return;
// TODO needs error MessageBox here and bomb out
+ WCHAR newPath[MAX_PATH];
for(UINT i = 0; i < foundCount; i++) {
- WCHAR newPath[MAX_PATH];
wcscpy_s(newPath, CEPath);
wcscat_s(newPath, findDataArray[i].cFileName);
CeDeleteFile(newPath);
@@ -265,7 +266,24 @@
CeRemoveDirectory(CEPath);
}
+void removeModule (LPCWSTR moduleConf) { // come here with name of .conf file
+ char mPath[MAX_PATH];
+ TCHAR ThisFile[MAX_PATH];
+ TCHAR WmPath[MAX_PATH];
+ copyconfs ((WCHAR*)moduleConf); // get the .conf file from the mobile
+ getModulePath (moduleConf, *mPath); // read the module files path
+ mbstowcs( WmPath, mPath, strlen(mPath)+1);
+ wcscpy_s (ThisFile, swordPath) ;
+ wcscat_s (ThisFile, WmPath);
+ deleteCEFiles (ThisFile); // delete all the module files and directory
+ wcscpy_s (ThisFile, swordPath) ;
+ wcscat_s (ThisFile, TEXT("mods.d\\"));
+ wcscat_s (ThisFile, moduleConf) ;
+ CeDeleteFile(ThisFile); // now delete the .conf file
+}
+
+
const char* doInstall() {
char swPath[MAX_PATH];
const char* swordPathString = swPath;
@@ -292,7 +310,6 @@
// wait for 10 seconds for the connection...
if ( (WaitForSingleObject(ri.heRapiInit, 10000) == WAIT_OBJECT_0) &&
SUCCEEDED(ri.hrRapiInit) ) {
-//deleteCEFiles (TEXT ("\\Storage Card\\sword\\modules\\texts\\rawtext\\phillips\\")); // test only REMOVE
// CreateDirectory does not have a problem if the directory
// named exists already
Directory::CreateDirectory( "mods.d" );
@@ -314,7 +331,7 @@
MessageBoxButtons::OK);
Application::Exit();
}
- // START this pass ok
+ // START this pass storing .conf file names ok
int n=0;
do {
// store the conf names (LPCWSTR FileInformation.cFileName) in an array
@@ -355,7 +372,9 @@
if(hFile != INVALID_HANDLE_VALUE)
{
do { // each .conf file in mods.d comes here with name etc
- // START this pass *NOT* ok
+ // START this pass storing .conf file name *NOT* ok while
+ // debugging - but OK outside debugger also at end of debug
+ // when testing with MessageBox
int len = wcslen(FileInformation.cFileName) + 1; // how much space is needed
TCHAR *newSpace = new WCHAR[len]; // allocate with new
// copy to new space
@@ -366,6 +385,7 @@
getModulePath (FileInformation.cFileName, *mPath);
String^ ptr = System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)modulePath);
// I don't have a clue how the above line works, but it does!
+ // better method used in MessageBox below
if (Directory::Exists(ptr)) {
// if there is no directory under 'modules' skip this
strcat (modulePath, "*");
@@ -421,19 +441,41 @@
CopyOver (wszSrcFile, tszCEDestFile);
} // if (Directory::Exists(ptr
+ delete ptr;
}while(FindNextFile(hFile, &FileInformation) == TRUE);
newConfs[n] = 0;
}
- /*
- // save this code - it shows char string in MessageBox
+/*
// debug only code
+ // save this code - it shows WCHAR string in MessageBox
n = -1;
while (newConfs[n++]) {
- String^ ptr = System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)(wstrtostr(newConfs[n])));
-MessageBox::Show(ptr, "This is the new .conf file", MessageBoxButtons::OK);
-}
+ // Convert to a System::String
+ // String ^systemstring = gcnew String((char *)newConfs[n]);
+ // TODO note that the above shows exactly what showed in SwordReader
+ // MessageBox when using renderText ....... REVISIT
+ String ^systemstring = gcnew String(newConfs[n]);
+ systemstring += " is the current module .conf file";
+ MessageBox::Show(systemstring, "This is the new .conf file",
+ MessageBoxButtons::OK);
+ delete systemstring;}
// end debug code
- */
+*/
+// removeModule (TEXT("phillips.conf")); // for debug
+ int Old = 0;
+ int New = 0;
+ do {
+ bool moduleDeleted = TRUE;
+ while (newConfs[New]){
+ if (!wcscmp (oldConfs[Old], newConfs[New++])) {
+ moduleDeleted = FALSE;
+ }
+ }
+ if (moduleDeleted) {
+ removeModule (oldConfs[Old]);
+ }
+ New = 0;
+ } while (oldConfs[++Old]);
if (modDir){
FindClose (modDir);
modDir = NULL;
@@ -443,6 +485,7 @@
hFile = NULL;
}
CeRapiUninit();
+ // TODO delete the two Conf arrays
// now remove all the files from the pc
Directory::Delete( "mods.d", true );
Directory::Delete( "modules", true );
@@ -450,7 +493,7 @@
} // if ( (WaitForSingleObject(ri.heRapiInit .....
else {
MessageBox::Show("Sorry, I could not connect to your mobile \
-device", "CeRapiInit failed", MessageBoxButtons::OK);
+device.", "CeRapiInit failed", MessageBoxButtons::OK);
CeRapiUninit();
Application::Exit();
}
More information about the sword-cvs
mailing list