[sword-svn] r79 - trunk/src/installer
bdrake at www.crosswire.org
bdrake at www.crosswire.org
Mon Dec 24 05:44:55 MST 2007
Author: bdrake
Date: 2007-12-24 05:44:55 -0700 (Mon, 24 Dec 2007)
New Revision: 79
Modified:
trunk/src/installer/doInstall.cpp
Log:
Not complete yet - but working up to the copying of new modules to mobile device. Now collects all the information required to install to the correct paths by reading the .conf files. Committed for evaluation.
Modified: trunk/src/installer/doInstall.cpp
===================================================================
--- trunk/src/installer/doInstall.cpp 2007-12-24 04:43:13 UTC (rev 78)
+++ trunk/src/installer/doInstall.cpp 2007-12-24 12:44:55 UTC (rev 79)
@@ -4,7 +4,11 @@
#include <rapi.h>
using namespace SRInstallMGR;
+using namespace System;
+using namespace System::IO;
+TCHAR swordPath[MAX_PATH];
+
const char *stristr(const char *haystack, const char *needle){ // not mine - nicked this off the 'net
if ( !*needle )
return haystack;
@@ -32,21 +36,20 @@
return buffer;
}
-const char* PrintDirectory(LPWSTR Path, UINT Indent){ // recurse through device from root
+TCHAR* PrintDirectory(LPWSTR Path, UINT Indent){ // recurse through device from root
DWORD foundCount;
LPCE_FIND_DATA findDataArray;
TCHAR wszSrcFile[MAX_PATH];
WCHAR tszDestFile[MAX_PATH];
WCHAR searchPath[MAX_PATH];
- TCHAR swordPath[MAX_PATH];
- char swPath[MAX_PATH];
- const char* swordPathString = swPath;
+
+
HANDLE hSrc, hDest;
- BYTE Buffer[4096];
+ BYTE Buffer[10000];
DWORD dwNumRead, dwNumWritten;
- wcscpy(searchPath, Path);
- wcscat(searchPath, L"*");
+ wcscpy_s(searchPath, Path);
+ wcscat_s(searchPath, L"*");
if(!CeFindAllFiles(searchPath, FAF_ATTRIBUTES | FAF_NAME, &foundCount, &findDataArray)) {
_tprintf( TEXT("*** CeFindAllFiles failed. ***\n"));
@@ -56,15 +59,14 @@
for(UINT i = 0; i < foundCount; i++) {
if(findDataArray[i].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // directory found
WCHAR newPath[MAX_PATH];
- wcscpy(newPath, Path);
- wcscat(newPath, findDataArray[i].cFileName);
- wcscat(newPath, L"\\");
+ wcscpy_s(newPath, Path);
+ wcscat_s(newPath, findDataArray[i].cFileName);
+ wcscat_s(newPath, L"\\");
PrintDirectory(newPath, Indent + 1);
- }
-
+ }
else if ((stristr(wstrtostr(Path), "MODS.D"))){ // not directory - this is a file
const char* modstr = stristr(wstrtostr(Path), "MODS.D");
- wcscpy(swordPath, Path);
+ wcscpy_s(swordPath, Path);
int len = strlen (modstr);
int swlen = wcslen (swordPath);
while (len--) swlen--;
@@ -79,15 +81,13 @@
// to have installed into two different locations - really!
*********************************************************************************/
- wprintf( TEXT("%s%s\n"),Path, findDataArray[i].cFileName); // for debugging
+ // wprintf( TEXT("%s%s\n"),Path, findDataArray[i].cFileName); // for debugging
// TODO - now add the filename to a list ready for later stage
// copy the file from Ce device to Pc
- wcscpy(wszSrcFile, Path);
-
-
- wcscat(wszSrcFile, findDataArray[i].cFileName);
- _tcscpy( tszDestFile, TEXT("mods.d\\"));
- wcscat( tszDestFile, findDataArray[i].cFileName);
+ wcscpy_s(wszSrcFile, Path);
+ wcscat_s(wszSrcFile, findDataArray[i].cFileName);
+ wcscpy_s( tszDestFile, TEXT("mods.d\\"));
+ wcscat_s( tszDestFile, findDataArray[i].cFileName);
hSrc = CeCreateFile(wszSrcFile, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hSrc) {
@@ -129,14 +129,27 @@
} // for(UINT i = 0; ........
if (findDataArray)
RapiFreeBuffer(findDataArray);
- swordPathString = wstrtostr(swordPath);
-// System::Windows::Forms::MessageBox::Show(swPath);
-// MessageBox(NULL, swPath, "swordPath",
-// MB_OK);
- return (swordPathString);
+ return (swordPath);
}
-const char* doInstall() {
+const char* doInstall() {
+ char swPath[MAX_PATH];
+ const char* swordPathString = swPath;
+ HANDLE modFile;
+ HANDLE hFile; // Handle to directory
+ WIN32_FIND_DATA FileInformation; // File information
+ DWORD BytesToRead;
+ DWORD BytesRead = 0;
+ BOOL isopen = FALSE;
+ WCHAR namstr[MAX_PATH];
+ WCHAR* name = namstr;
+ char mPath[MAX_PATH];
+ char *modulePath = mPath;
+ char m2Path[MAX_PATH];
+ char *modName = m2Path;
+ char longstr[10000];
+ LPVOID lpBuffer = longstr;
+ const char *pathstr;
RAPIINIT ri = { sizeof(RAPIINIT) };
if ( SUCCEEDED(CeRapiInitEx(&ri)))
@@ -144,7 +157,13 @@
// wait for 10 seconds for the connection...
if ( (WaitForSingleObject(ri.heRapiInit, 10000) == WAIT_OBJECT_0) &&
SUCCEEDED(ri.hrRapiInit) ) {
- const char* swordPath = PrintDirectory( L"\\", 0);
+ TCHAR* swordPath = PrintDirectory( L"\\", 0);
+ if (*swordPath != NULL)
+ swordPathString = wstrtostr(swordPath);
+ // we now have TCHAR *swordPath and char *swordPathString
+ // both holding the full sword path on the mobile device
+ // and the mods.d directory on the pc now containing copies of
+ // all the mods.d files that are on the mobile device
CeRapiUninit();
STARTUPINFO si;
PROCESS_INFORMATION pi;
@@ -163,10 +182,76 @@
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
- //MessageBox::Show("Well, looks like we got here", "Success!!!",
- // MessageBoxButtons::OK);
- return (swordPath);
+
+ hFile = ::FindFirstFile(TEXT("mods.d\\*.conf"), &FileInformation);
+ if(hFile != INVALID_HANDLE_VALUE)
+ {
+ do {
+ // MessageBox::Show("in while loop now", "Testing",
+ // MessageBoxButtons::OK);
+ // each .conf file in mods.d comes here with name etc
+ wcscpy ( name, TEXT("mods.d\\"));
+ wcscat (name, FileInformation.cFileName);
+ BytesToRead = sizeof(longstr)-1;
+ modFile = CreateFile(name, GENERIC_READ, FILE_SHARE_READ,
+ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ if (INVALID_HANDLE_VALUE == modFile) {
+ MessageBox::Show("Sorry, I can't seem to read files in your mods.d directory. Do you have a mods.d directory where you put me?", "Process Failed",
+ MessageBoxButtons::OK);
+ Application::Exit();
+ return(NULL);
+ }
+ // read the entire .conf file into our buffer - biggest I know of
+ // now is a 5k .conf, so I've gone for a 10,000 byte buffer ....
+
+ isopen = ReadFile(modFile, &longstr, BytesToRead, &BytesRead, NULL);
+ // we ought to check for success 'if isopen' or something
+ CloseHandle(modFile);
+ pathstr = stristr (longstr, "DataPath=.");
+ if (!pathstr){
+ MessageBox::Show("Failed to make string match for DataPath=.", "Leaving now",
+ MessageBoxButtons::OK);
+ Application::Exit();
}
+ pathstr+=10;
+ strcpy (modulePath, "");// this will need to be the swordPath
+ int i = 0;
+ int p = (strlen(modulePath));
+ p--;
+ while (*(pathstr+i) != 10 && *(pathstr+i) != 13) { // some confs have cr/lf and some only lf (why?)
+ *(modulePath+p++) = *(pathstr+i);
+ i++;
+ }
+// --p; // if we don't want trailing slash
+ *(modulePath+p) = 0; // at end of trailing slash in pathstring
+ // TODO - lexdicts are handled differently in pathing
+
+
+ // TODO - copy each module .conf and files to mobile device
+ // only if there are files for that module in modules directory
+
+
+ /*
+ // here is the method I'll use for removing a single file
+ char FileToDelete[]= "mods.d\\gill.conf";
+ char *f2del = FileToDelete;
+ String^ ptr = System::Runtime::InteropServices::Marshal::PtrToStringAnsi((IntPtr)f2del);
+ // I don't have a clue how the above line works, but it does!
+ File::Delete(ptr);
+ */
+
+ }while(::FindNextFile(hFile, &FileInformation) == TRUE);
+ }
+ ::FindClose(hFile); // Close handle
+ // now remove all the files from the pc
+ Directory::Delete( "mods.d", true );
+ Directory::Delete( "modules", true );
+ // but leave with the directories in place for next time - or could
+ // move the creates to the beginning of this function - maybe tidier?
+ Directory::CreateDirectory( "mods.d" );
+ Directory::CreateDirectory( "modules" );
+ return (swordPathString);
+ }
else {
MessageBox::Show("Sorry, I could not connect to your mobile device", "CeRapiInit failed",
MessageBoxButtons::OK);
@@ -185,5 +270,6 @@
Application::Exit();
}
Application::Exit();
+return(0); // can't get here - but avoids warning
}
More information about the sword-cvs
mailing list