From 2ebb53adcd4663ac2f1da74972b7b21d53b0ce53 Mon Sep 17 00:00:00 2001 From: "george.hazan" Date: Thu, 26 May 2011 20:18:42 +0000 Subject: patch for dbeditorpp: C++ support, other improvements git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@122 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- dbeditorpp/exportimport.cpp | 384 ++++++++++++++++++++++++++------------------ 1 file changed, 225 insertions(+), 159 deletions(-) (limited to 'dbeditorpp/exportimport.cpp') diff --git a/dbeditorpp/exportimport.cpp b/dbeditorpp/exportimport.cpp index b398b77..20442a1 100644 --- a/dbeditorpp/exportimport.cpp +++ b/dbeditorpp/exportimport.cpp @@ -1,11 +1,14 @@ #include "headers.h" +int Mode; +HWND hwnd2importWindow; + int Openfile(char *outputFile, const char *module) { OPENFILENAME ofn = {0}; char filename[MAX_PATH] = ""; - char *filter = "INI Files\0*.ini\0All Files\0*.*\0"; - int r; + char filter[MAX_PATH]; + mir_snprintf(filter, SIZEOF(filter), "%s%c*.ini%c%s%c*.*%c", Translate("INI Files"), 0, 0, Translate("All Files"), 0, 0); char *title = Translate("Export to file"); if (module) @@ -38,24 +41,56 @@ int Openfile(char *outputFile, const char *module) ofn.nMaxFile = MAX_PATH; ofn.lpstrDefExt = "ini"; - r = GetSaveFileName(&ofn); - if (!r) + if (!GetSaveFileName(&ofn)) return 0; lstrcpy(outputFile,filename); return 1; } +char* StrReplace (char* Search, char* Replace, char* Resource) +{ + int i = 0; + int SearchLen = (int)_tcslen(Search); + char* Work = mir_tstrdup(Replace); + int ReplaceLen = (int)_tcslen(Work); + + char* Pointer = _tcsstr(Resource, Search); + + while (Pointer != NULL) + { + int PointerLen = (int)_tcslen(Pointer); + int ResourceLen = (int)_tcslen(Resource); + + char* NewText = (char*)mir_calloc((ResourceLen - SearchLen + ReplaceLen + 1)*sizeof(char)); + + _tcsncpy(NewText, Resource, ResourceLen - PointerLen); + _tcscat(NewText, Work); + _tcscat(NewText, Pointer + SearchLen); + + Resource = (char*)mir_realloc(Resource, (ResourceLen - SearchLen + ReplaceLen + 1)*sizeof(char)); + + for (i = 0; i < (ResourceLen - SearchLen + ReplaceLen); i++) + Resource[i] = NewText[i]; + Resource[i] = 0; + mir_free(NewText); + + Pointer = _tcsstr(Resource + (ResourceLen - PointerLen + ReplaceLen), Search); + } + mir_free(Work); + + return Resource; +} + void exportModule(HANDLE hContact, char* module, FILE* file) { char tmp[32]; ModuleSettingLL settinglist; struct ModSetLinkLinkItem *setting; - if (IsModuleEmpty(hContact,module)) return; EnumSettings(hContact,module,&settinglist); // print the module header.. - fprintf(file, "[%s]\n", module); + fprintf(file, "\n[%s]", module); setting = settinglist.first; while(setting) { @@ -65,69 +100,60 @@ void exportModule(HANDLE hContact, char* module, FILE* file) switch (dbv.type) { case DBVT_BYTE: - fprintf(file, "%s=b%s\n", setting->name, itoa(dbv.bVal,tmp,10)); + fprintf(file, "\n%s=b%s", setting->name, itoa(dbv.bVal,tmp,10)); + DBFreeVariant(&dbv); break; case DBVT_WORD: - fprintf(file, "%s=w%s\n", setting->name, itoa(dbv.wVal,tmp,10)); + fprintf(file, "\n%s=w%s", setting->name, itoa(dbv.wVal,tmp,10)); + DBFreeVariant(&dbv); break; case DBVT_DWORD: - fprintf(file, "%s=d%s\n", setting->name, itoa(dbv.dVal,tmp,10)); + fprintf(file, "\n%s=d%s", setting->name, itoa(dbv.dVal,tmp,10)); + DBFreeVariant(&dbv); break; case DBVT_ASCIIZ: - fprintf(file, "%s=s%s\n", setting->name, dbv.pszVal); - break; case DBVT_UTF8: - fprintf(file, "%s=u%s\n", setting->name, dbv.pszVal); - /*{ - //convert \r to STX and \n to ETX - char *end = strchr(dbv.pszVal, '\r'); - while (end) // convert \r to STX - { - *end = 2; - end = strchr(end+1, '\r'); - } - end = strchr(dbv.pszVal, '\n'); - while (end) // convert \n to ETX - { - *end = 3; - end = strchr(end+1, '\n'); - } - - if (dbv.type == DBVT_UTF8) - fprintf(file, "%s=u%s\n", setting->name, dbv.pszVal); - else - fprintf(file, "%s=s%s\n", setting->name, dbv.pszVal); - }*/ - break; + if (strchr(dbv.pszVal, '\r')) + { + char *end = StrReplace("\\", "\\\\", dbv.pszVal); + end = StrReplace("\r", "\\r", end); + end = StrReplace("\n", "\\n", end); + fprintf(file, "\n%s=g%s", setting->name, end); + break; + } + if (dbv.type == DBVT_UTF8) + fprintf(file, "\n%s=u%s", setting->name, dbv.pszVal); + else + fprintf(file, "\n%s=s%s", setting->name, dbv.pszVal); + DBFreeVariant(&dbv); + break; case DBVT_BLOB: { int j; char *data = NULL; - if (!(data = (char*)malloc( 3*(dbv.cpbVal+1)) )) + if (!(data = (char*)mir_alloc( 3*(dbv.cpbVal+1)*sizeof(char)) )) break; data[0] = '\0'; for (j=0; jname , data); - safe_free(data); + fprintf(file,"\n%s=n%s",setting->name , data); + mir_free(data); } + DBFreeVariant(&dbv); break; } } - DBFreeVariant(&dbv); setting = (struct ModSetLinkLinkItem *)setting->next; } - fprintf(file, "\n"); FreeModuleSettingLL(&settinglist); - } -static char *NickFromHContact(HANDLE hContact) +char *NickFromHContact(HANDLE hContact) { static char nick[512] = ""; @@ -136,7 +162,7 @@ static char *NickFromHContact(HANDLE hContact) char szProto[256]; int loaded = 0; - if (GetValue(hContact,"Protocol","p",szProto,sizeof(szProto))) + if (GetValue(hContact,"Protocol","p",szProto,SIZEOF(szProto))) loaded = IsProtocolLoaded(szProto); if (!szProto[0] || !loaded) @@ -145,13 +171,13 @@ static char *NickFromHContact(HANDLE hContact) if (szProto[0]) { - if (GetValue(hContact,szProto,"Nick",name,sizeof(name))) - mir_snprintf(nick, sizeof(nick),"%s (%s)", name, szProto); + if (GetValue(hContact,szProto,"Nick",name,SIZEOF(name))) + mir_snprintf(nick, SIZEOF(nick),"%s (%s)", name, szProto); else - mir_snprintf(nick, sizeof(nick),"(UNKNOWN) (%s)", szProto); + mir_snprintf(nick, SIZEOF(nick),"(UNKNOWN) (%s)", szProto); } else - mir_snprintf(nick, sizeof(nick),"(UNKNOWN)"); + mir_snprintf(nick, SIZEOF(nick),"(UNKNOWN)"); } else { @@ -161,11 +187,11 @@ static char *NickFromHContact(HANDLE hContact) uid = (char*)CallProtoService(szProto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0); if ((int)uid!=CALLSERVICE_NOTFOUND && uid) { - GetValue(hContact, szProto, uid, szUID, sizeof(szUID)); - mir_snprintf(nick, sizeof(nick), "%s *(%s)*<%s>*{%s}*", (char*)GetContactName(hContact,szProto,0), szProto, uid, szUID); + GetValue(hContact, szProto, uid, szUID, SIZEOF(szUID)); + mir_snprintf(nick, SIZEOF(nick), "%s *(%s)*<%s>*{%s}*", (char*)GetContactName(hContact,szProto,0), szProto, uid, szUID); } else - mir_snprintf(nick, sizeof(nick), "%s (%s)", (char*)GetContactName(hContact,szProto,0), szProto); + mir_snprintf(nick, SIZEOF(nick), "%s (%s)", (char*)GetContactName(hContact,szProto,0), szProto); } } @@ -197,15 +223,20 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. if (module == NULL) { - fprintf(file, "SETTINGS:\n\n"); + fprintf(file, "SETTINGS:\n"); mod = modlist.first; - while(mod) // null contact first + while(mod) { + if (IsModuleEmpty(hContact, mod->name)) + { + mod = (struct ModSetLinkLinkItem *)mod->next; + continue; + } exportModule(hContact, mod->name, file); mod = (struct ModSetLinkLinkItem *)mod->next; + if (mod) + fprintf(file, "\n"); } - fprintf(file, "\n"); - } else { @@ -224,7 +255,7 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. char szProto[256]; int loaded = 0; - if (GetValue(hContact,"Protocol","p",szProto,sizeof(szProto))) + if (GetValue(hContact,"Protocol","p",szProto,SIZEOF(szProto))) loaded = IsProtocolLoaded(szProto); if ((loaded && Mode == MODE_UNLOADED) || (!loaded && Mode == MODE_LOADED)) @@ -234,23 +265,28 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. } } - fprintf(file, "CONTACT: %s\n\n", NickFromHContact(hContact)); + fprintf(file, "CONTACT: %s\n", NickFromHContact(hContact)); if (module == NULL) // export all modules { mod = modlist.first; while(mod) { + if (IsModuleEmpty(hContact, mod->name)) + { + mod = (struct ModSetLinkLinkItem *)mod->next; + continue; + } exportModule(hContact, mod->name, file); mod = (struct ModSetLinkLinkItem *)mod->next; + if (mod) + fprintf(file, "\n"); } } else // export module { exportModule(hContact, module, file); } - - fprintf(file, "\n"); hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)(HANDLE)hContact, 0); } } @@ -260,28 +296,33 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. if (!module) // exporting every module { if (hContact) - fprintf(file, "CONTACT: %s\n\n", NickFromHContact(hContact)); + fprintf(file, "CONTACT: %s\n", NickFromHContact(hContact)); else - fprintf(file, "SETTINGS:\n\n"); + fprintf(file, "SETTINGS:\n"); mod = modlist.first; while(mod) { + if (IsModuleEmpty(hContact, mod->name)) + { + mod = (struct ModSetLinkLinkItem *)mod->next; + continue; + } exportModule(hContact, mod->name, file); mod = (struct ModSetLinkLinkItem *)mod->next; + if (mod) + fprintf(file, "\n"); } } else { if (hContact) - fprintf(file, "FROM CONTACT: %s\n\n", NickFromHContact(hContact)); + fprintf(file, "FROM CONTACT: %s\n", NickFromHContact(hContact)); else - fprintf(file, "SETTINGS:\n\n"); + fprintf(file, "SETTINGS:\n"); exportModule(hContact, module, file); } - - fprintf(file, "\n"); } fclose(file); @@ -289,7 +330,6 @@ void exportDB(HANDLE hContact, char* module) // hContact == -1 export entire db. } FreeModuleSettingLL(&modlist); - } @@ -306,7 +346,7 @@ HANDLE CheckNewContact(char *myProto, char *uid, char *myName) { if (!mir_strcmp(szProto, myProto)) { - if (GetValue(hContact, szProto, uid, szName, sizeof(szName)) && + if (GetValue(hContact, szProto, uid, szName, SIZEOF(szName)) && !mir_strcmp(szName, myName)) { //char msg[1024]; @@ -325,6 +365,42 @@ HANDLE CheckNewContact(char *myProto, char *uid, char *myName) } +TCHAR* __stdcall rtrim(TCHAR *string) +{ + TCHAR* p = string + _tcslen(string) - 1; + + while (p >= string) { + if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') + break; + + *p-- = 0; + } + return string; +} + +HANDLE Clist_GroupExists(WCHAR *tszGroup) +{ + unsigned int i = 0; + WCHAR* _t = 0; + char str[10]; + INT_PTR result = 0; + DBVARIANT dbv = {0}; + int match; + + do { + _itoa(i, str, 10); + result = DBGetContactSettingTString(0, "CListGroups", str, &dbv); + if(!result) { + match = (!lstrcmpW(tszGroup, (LPCWSTR)&dbv.ptszVal[1]) && (lstrlenW(tszGroup) == lstrlenW((LPCWSTR)&dbv.ptszVal[1]))); + DBFreeVariant(&dbv); + if(match) + return((HANDLE)(i + 1)); + } + i++; + } + while(result == 0); + return(0); +} void importSettings(HANDLE hContact, char *importstring ) { @@ -337,33 +413,24 @@ void importSettings(HANDLE hContact, char *importstring ) while (importstring != NULL) { i=0; - if (importstring[i] == '\n') + rtrim(importstring); + if (importstring[i] == '\0') { importstring = strtok(NULL, "\n"); continue; } else if (!strncmp(&importstring[i],"SETTINGS:",strlen("SETTINGS:"))) { - hContact = 0; -/* - end = strstr(&importstring[i], "\n"); - if (end) - { - i = end - &importstring[i]; - } -*/ + importstring = strtok(NULL, "\n"); + continue; } else if (!strncmp(&importstring[i],"CONTACT:", strlen("CONTACT:"))) { - int len, add = 1; - hContact = INVALID_HANDLE_VALUE; - //end = strstr(&importstring[i], "\n"); - - i = i + strlen("CONTACT:"); - len = strlen(&importstring[i]); + i = i + (int)strlen("CONTACT:"); + len = (int)strlen(&importstring[i]); if (len > 10) { @@ -373,21 +440,21 @@ void importSettings(HANDLE hContact, char *importstring ) p1 = strrchr(&importstring[i], '>*{'); p2 = strrchr(&importstring[i], '}*'); - if (p1 && p2 && p1+3 < p2 && p2-p1 < sizeof(szUID)) + if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(szUID)) { strncpy(szUID, p1+1, p2-p1-2); p1 = strrchr(&importstring[i], ')*<'); p2 = strrchr(&importstring[i], '>*{'); - if (p1 && p2 && p1+3 < p2 && p2-p1 < sizeof(uid)) + if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(uid)) { strncpy(uid, p1+1, p2-p1-3); p1 = strrchr(&importstring[i], ' *('); p2 = strrchr(&importstring[i], ')*<'); - if (p1 && p2 && p1+3 < p2 && p2-p1 < sizeof(szProto)) + if (p1 && p2 && p1+3 < p2 && p2-p1 < SIZEOF(szProto)) { char *protouid; strncpy(szProto, p1+1, p2-p1-3); @@ -408,16 +475,9 @@ void importSettings(HANDLE hContact, char *importstring ) if (hContact == INVALID_HANDLE_VALUE) { HANDLE temp = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0); - if (temp) hContact = temp; } -/* - if (end) - { - i = end - &importstring[i]; - } -*/ } else if (importstring[i] == '[' && !strchr(&importstring[i+1],'=') )// get the module { @@ -427,8 +487,7 @@ void importSettings(HANDLE hContact, char *importstring ) } } else if (importstring[i] == '-' && importstring[i+1] == '[' && - !strchr(&importstring[i+2],'=') && - hContact != INVALID_HANDLE_VALUE)// get the module + !strchr(&importstring[i+2],'='))// get the module { if (end = strpbrk(&importstring[i+2], "]")) { if ((end+1) != '\0') *end = '\0'; @@ -436,8 +495,7 @@ void importSettings(HANDLE hContact, char *importstring ) deleteModule(module, hContact, 1); } } - else if (strstr(&importstring[i], "=") && module[0] && - hContact != INVALID_HANDLE_VALUE) // get the setting + else if (strstr(&importstring[i], "=") && module[0]) // get the setting { if (end = strpbrk(&importstring[i+1], "=")) { if ((end+1) != '\0') *end = '\0'; @@ -445,6 +503,22 @@ void importSettings(HANDLE hContact, char *importstring ) // get the type type = *(end+1); + if (lstrcmp(module, "CList") == 0 && lstrcmp(setting, "Group") == 0) + { + WCHAR* GroupName = mir_a2u(end+2); + if (!GroupName) + continue; + HANDLE GroupHandle = Clist_GroupExists(GroupName); + if(GroupHandle == 0) { + GroupHandle = (HANDLE)CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)GroupName); + + if(GroupHandle) { + CallService(MS_CLUI_GROUPADDED, (WPARAM)GroupHandle, 0); + CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)GroupHandle, 1); + } + } + mir_free(GroupName); + } switch (type) { case 'b': @@ -463,35 +537,25 @@ void importSettings(HANDLE hContact, char *importstring ) DBWriteContactSettingDword(hContact, module, setting, (DWORD)value); break; case 's': - case 'u': + case 'S': DBWriteContactSettingString(hContact,module, setting, (end+2)); break; - case 'S': + case 'g': + case 'G': + { char *pstr; + for(pstr=end+2;*pstr;pstr++){ + if(*pstr=='\\'){ + switch(pstr[1]){ + case 'n': *pstr='\n'; break; + case 't': *pstr='\t'; break; + case 'r': *pstr='\r'; break; + default: *pstr=pstr[1]; break; + } + MoveMemory(pstr+1,pstr+2,lstrlenA(pstr+2)+1); + } } } + case 'u': case 'U': DBWriteContactSettingStringUtf(hContact,module, setting, (end+2)); - /*{ - char *string; - string = (end+2); - end = strchr(string, '\r'); - if (end) // remove \r - *end = 0; - end = strchr(string, 2); - while (end) // convert STX back to \r - { - *end = '\r'; - end = strchr(++end, 2); - } - end = strchr(string, 3); - while (end) // convert ETX back to \n - { - *end = '\n'; - end = strchr(++end, 3); - } - if (type == 'u' || type == 'U') - DBWriteContactSettingStringUtf(hContact,module, setting, string); - else - DBWriteContactSettingString(hContact,module, setting, string); - }*/ break; case 'l': case 'L': @@ -499,26 +563,22 @@ void importSettings(HANDLE hContact, char *importstring ) break; case 'n': case 'N': - WriteBlobFromString(hContact,module,setting,(end+2),strlen((end+2))); + WriteBlobFromString(hContact, module, setting, (end+2), (int)strlen((end+2))); break; } } } importstring = strtok(NULL, "\n"); } - SetCursor(LoadCursor(NULL,IDC_ARROW)); } - -#define crlf_string "\x02\x03\0" - -BOOL CALLBACK ImportDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK ImportDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_INITDIALOG) { hwnd2importWindow = hwnd; - SetWindowLong(hwnd,GWL_USERDATA,lParam); + SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam); TranslateDialogDefault(hwnd); SendDlgItemMessage(hwnd, IDC_TEXT, EM_LIMITTEXT, (WPARAM)sizeof(TCHAR)*0x7FFFFFFF, 0); } @@ -530,12 +590,12 @@ BOOL CALLBACK ImportDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case IDC_CRLF: { int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT)); - char *string = _alloca(length+4); + char *string = (char*)_alloca(length+3); int Pos = 2; if (length) { - int Range = SendDlgItemMessageA(hwnd,IDC_TEXT,EM_GETSEL,0,0); + int Range = SendDlgItemMessage(hwnd,IDC_TEXT,EM_GETSEL,0,0); int Min = LOWORD(Range); int Max = HIWORD(Range); @@ -543,35 +603,35 @@ BOOL CALLBACK ImportDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) GetDlgItemText(hwnd, IDC_TEXT, string, length+1); if (Min == -1) - memcpy(string, crlf_string, 3); + memcpy(string, crlf_string, SIZEOF(crlf_string)); else if (Max == -1 || Max >= length) - memcpy(&string[Min], crlf_string, 3); + memcpy(&string[Min], crlf_string, SIZEOF(crlf_string)); else if (Max-Min > 2) { - memcpy(&string[Min], crlf_string, 2); + memcpy(&string[Min], crlf_string, SIZEOF(crlf_string)); memmove(&string[Min+2], &string[Max], length - Max + 1); } else { memmove(&string[Min+2], &string[Max], length - Max + 1); - memcpy(&string[Min], crlf_string, 2); + memcpy(&string[Min], crlf_string, SIZEOF(crlf_string)); } if (Min) Pos += Min; } else - memcpy(string, crlf_string, 3); + memcpy(string, crlf_string, SIZEOF(crlf_string)); SetDlgItemText(hwnd, IDC_TEXT, string); - SendDlgItemMessageA(hwnd,IDC_TEXT,EM_SETSEL,Pos,Pos); + SendDlgItemMessage(hwnd,IDC_TEXT,EM_SETSEL,Pos,Pos); SetFocus(GetDlgItem(hwnd, IDC_TEXT)); } break; case IDOK: { - HANDLE hContact = (HANDLE)GetWindowLong(hwnd,GWL_USERDATA); + HANDLE hContact = (HANDLE)GetWindowLongPtr(hwnd,GWLP_USERDATA); int length = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT)); char *string; if (length) @@ -598,52 +658,59 @@ void ImportSettingsMenuItem(HANDLE hContact) if (hwnd2importWindow) DestroyWindow(hwnd2importWindow); - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_IMPORT), 0,ImportDlgProc, (LPARAM)hContact); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_IMPORT), 0, ImportDlgProc, (LPARAM)hContact); } int Openfile2Import(char *outputFiles) { OPENFILENAME ofn = {0}; - char *filter = "INI Files\0*.ini\0All Files\0*.*\0"; + char filter[MAX_PATH]; + mir_snprintf(filter, SIZEOF(filter), "%s%c*.ini%c%s%c*.*%c", Translate("INI Files"), 0, 0, Translate("All Files"), 0, 0); char *title = Translate("Import from files"); - ofn.lStructSize = sizeof(ofn); - ofn.lpstrFile = outputFiles; + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.lpstrFilter = filter; + ofn.hwndOwner = 0; + ofn.lpstrFile = outputFiles; + ofn.nMaxFile = MAX_PATH; + ofn.nMaxFileTitle = MAX_PATH; ofn.Flags = OFN_HIDEREADONLY | OFN_SHAREAWARE | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER; ofn.lpstrTitle = title; - ofn.nMaxFile = MAX_PATH*10; - if (!GetOpenFileName(&ofn)) return 0; - return ofn.nFileOffset; + return 1; +} + +BOOL Exists(LPCTSTR strName) +{ + return GetFileAttributes(strName) != INVALID_FILE_ATTRIBUTES; } -void ImportSettingsFromFileMenuItem(HANDLE hContact) +void ImportSettingsFromFileMenuItem(HANDLE hContact, char* FilePath) { char szFileNames[MAX_PATH*10] = {0}; char szPath[MAX_PATH] = ""; char szFile[MAX_PATH]; - DWORD offset = Openfile2Import(szFileNames); int index = 0; HANDLE hFile, hMap; PBYTE pFile = NULL; - - if (offset) + if (lstrcmp(FilePath, "") == 0) + Openfile2Import(szFileNames); + else + { + if(Exists(FilePath)) + lstrcpy(szFileNames, FilePath); + else + lstrcpy(szFileNames, ""); + } + if (!lstrcmp(szFileNames, "") == 0) { - if (strlen(szFileNames) < offset) - { - index += offset; - strncpy(szPath, szFileNames, offset); - strcat(szPath, "\\"); - } - while(szFileNames[index]) { strcpy(szFile, szPath); strcat(szFile, &szFileNames[index]); - index += strlen(&szFileNames[index])+1; + index += (int)strlen(&szFileNames[index])+1; hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) @@ -653,10 +720,10 @@ void ImportSettingsFromFileMenuItem(HANDLE hContact) hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (hMap) { - pFile = MapViewOfFile(hMap, FILE_MAP_COPY, 0, 0 ,0); + pFile = (PBYTE)MapViewOfFile(hMap, FILE_MAP_COPY, 0, 0 ,0); if (pFile) { - importSettings(hContact, pFile); + importSettings(hContact, (char*)pFile); UnmapViewOfFile(pFile); } CloseHandle(hMap); @@ -669,8 +736,7 @@ void ImportSettingsFromFileMenuItem(HANDLE hContact) break; } - - refreshTree(1); + if (lstrcmp(FilePath, "") == 0) + refreshTree(1); } - } -- cgit v1.2.3