From 49789773e2797383c866dca470fb99e80cb49e41 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sun, 4 Feb 2018 05:29:51 +0000 Subject: [PATCH] Win32: implement further UTF8 support --- projects/msw/xestiacal.vcxproj | 8 ++--- source/common/file.cpp | 22 ++++++++++++- source/common/file.h | 6 ++-- source/forms/main/frmMain.cpp | 10 +++--- source/forms/preferences/frmPreferences.cpp | 4 +-- .../CalendarDataStorage.cpp | 4 +-- .../CalendarDataStorage/CalendarDataStorage.h | 4 +++ source/objects/calendarlist/CalendarList.cpp | 6 ++-- .../calendarobject/CalendarObject-Save.cpp | 22 ++++++++++++- .../objects/calendarobject/CalendarObject.cpp | 32 ++++++++++++++++--- .../objects/calendarobject/CalendarObject.h | 4 +++ source/widgets/XCCalendarDay.cpp | 1 - 12 files changed, 96 insertions(+), 27 deletions(-) diff --git a/projects/msw/xestiacal.vcxproj b/projects/msw/xestiacal.vcxproj index 45c2117..87e9dcf 100644 --- a/projects/msw/xestiacal.vcxproj +++ b/projects/msw/xestiacal.vcxproj @@ -358,7 +358,7 @@ .\..\..\lib\vc_x64_lib\mswud;.\..\..\include;.;.\..\..\samples;%(AdditionalIncludeDirectories) - wxmsw30ud_core.lib;wxbase30ud.lib;wxtiffd.lib;wxjpegd.lib;wxpngd.lib;wxzlibd.lib;wxregexud.lib;wxexpatd.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;%(AdditionalDependencies) + wxmsw30ud_core.lib;wxbase30ud.lib;wxtiffd.lib;wxjpegd.lib;wxpngd.lib;wxzlibd.lib;wxregexud.lib;wxexpatd.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;Shlwapi.dll;%(AdditionalDependencies) vc_mswud_x64\minimal.exe true .\..\..\lib\vc_x64_lib;%(AdditionalLibraryDirectories) @@ -403,7 +403,7 @@ .\..\..\lib\vc_x64_dll\mswu;.\..\..\include;.;.\..\..\samples;%(AdditionalIncludeDirectories) - wxmsw30u_core.lib;wxbase30u.lib;wxtiff.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;%(AdditionalDependencies) + wxmsw30u_core.lib;wxbase30u.lib;wxtiff.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;Shlwapi.dll;%(AdditionalDependencies) vc_mswu_x64\minimal.exe true K:\LibraryBuild\Win7\lib\vc_x64_dll;%(AdditionalLibraryDirectories) @@ -452,7 +452,7 @@ .\..\..\lib\vc_x64_dll\mswud;.\..\..\include;.;.\..\..\samples;%(AdditionalIncludeDirectories) - wxmsw30ud_core.lib;wxmsw30ud_html.lib;wxbase30ud.lib;wxmsw30ud_adv.lib;sqlite3.lib;libcurl.lib;libxml2.dll.a;wxtiffd.lib;wxjpegd.lib;wxpngd.lib;wxzlibd.lib;wxregexud.lib;wxexpatd.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;security.lib;cryptui.lib;crypt32.lib;%(AdditionalDependencies) + wxmsw30ud_core.lib;wxmsw30ud_html.lib;wxbase30ud.lib;wxmsw30ud_adv.lib;sqlite3.lib;libcurl.lib;libxml2.dll.a;wxtiffd.lib;wxjpegd.lib;wxpngd.lib;wxzlibd.lib;wxregexud.lib;wxexpatd.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;security.lib;cryptui.lib;crypt32.lib;Shlwapi.lib;%(AdditionalDependencies) vc_mswuddll_x64\xestiacal.exe true $(SQLITE_64BIT);$(SFML_64BIT)\lib;$(LIBXML2_64BIT)\lib;$(CURL_64BIT)\builds\\libcurl-vc-x64-release-dll-zlib-dll-ipv6-sspi-winssl\lib;$(WXWIDGETS_64BIT_DEBUG)\lib\vc_x64_dll;%(AdditionalLibraryDirectories) @@ -497,7 +497,7 @@ .\..\..\lib\vc_x64_dll\mswu;.\..\..\include;.;.\..\..\samples;%(AdditionalIncludeDirectories) - wxmsw30u_core.lib;wxmsw30u_html.lib;wxbase30u.lib;wxmsw30u_adv.lib;sqlite3.lib;wxtiff.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;%(AdditionalDependencies) + wxmsw30u_core.lib;wxmsw30u_html.lib;wxbase30u.lib;wxmsw30u_adv.lib;sqlite3.lib;wxtiff.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;kernel32.lib;user32.lib;gdi32.lib;comdlg32.lib;winspool.lib;winmm.lib;shell32.lib;comctl32.lib;ole32.lib;oleaut32.lib;uuid.lib;rpcrt4.lib;advapi32.lib;wsock32.lib;wininet.lib;Shlwapi.lib;%(AdditionalDependencies) vc_mswudll_x64\xestiacal.exe true $(SQLITE_64BIT);$(SFML_64BIT)\lib;$(LIBXML2_64BIT)\lib;$(CURL_64BIT)\builds\libcurl-vc-x64-release-dll-zlib-static-ipv6-sspi-winssl\lib;$(WXWIDGETS_64BIT)\lib\vc_x64_dll;%(AdditionalLibraryDirectories) diff --git a/source/common/file.cpp b/source/common/file.cpp index 076752d..9e4e448 100644 --- a/source/common/file.cpp +++ b/source/common/file.cpp @@ -22,7 +22,7 @@ using namespace std; bool FileExists(std::string filename){ -#if defined (__WIN32__) +#if defined (WIN32) #else @@ -36,4 +36,24 @@ bool FileExists(std::string filename){ return true; +} + +bool FileExists(std::wstring filename) { + +#if defined (WIN32) + + return PathFileExists(filename.c_str()); + +#else + + struct stat bufferData; + + if (stat(filename.c_str(), &bufferData) == -1) { + return false; + } + +#endif + + return true; + } \ No newline at end of file diff --git a/source/common/file.h b/source/common/file.h index 63cc2ca..69303d7 100644 --- a/source/common/file.h +++ b/source/common/file.h @@ -21,12 +21,14 @@ #include #include -#if defined (__WIN32__) - +#if defined (WIN32) +#include +#include #else #include #endif bool FileExists(std::string filename); +bool FileExists(std::wstring filename); #endif \ No newline at end of file diff --git a/source/forms/main/frmMain.cpp b/source/forms/main/frmMain.cpp index 11246ae..f7e2c1f 100644 --- a/source/forms/main/frmMain.cpp +++ b/source/forms/main/frmMain.cpp @@ -211,11 +211,11 @@ void frmMain::LoadAccountData(){ // Build the path. - string calendarListFilename = string(GetUserDir().mb_str()); + string calendarListFilename = string(GetUserDir().ToUTF8()); calendarListFilename += "accounts/"; - calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).mb_str()); + calendarListFilename += string(preferences->accounts.GetAccountDirectory(accountSeek).ToUTF8()); calendarListFilename += "."; - calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).mb_str()); + calendarListFilename += string(preferences->accounts.GetAccountType(accountSeek).ToUTF8()); // Get the list of calendars. @@ -235,7 +235,7 @@ void frmMain::LoadAccountData(){ // Set the calendar ID. - CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).mb_str()), calendarList.calendarShortName[calendarSeek]); + CDSGetCalendarInfo calendarInfo = calendarData.GetCalendar(string(preferences->accounts.GetAccountName(accountSeek).ToUTF8()), calendarList.calendarShortName[calendarSeek]); calendarList.calendarStorageID[calendarSeek] = calendarInfo.calendarID; // Find the entries and load each entry. @@ -629,7 +629,7 @@ void frmMain::ProcessCalendar( wxCommandEvent& event ) accountDirectoryPath += "accounts/"; accountDirectoryPath += string(preferences->accounts.GetAccountDirectory(calendarInfo->accountPreferencesID).ToUTF8()); accountDirectoryPath += "."; - accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarInfo->accountPreferencesID).mb_str()); + accountDirectoryPath += string(preferences->accounts.GetAccountType(calendarInfo->accountPreferencesID).ToUTF8()); accountDirectoryPath += "/"; // Generate a UUID for the new calendar. diff --git a/source/forms/preferences/frmPreferences.cpp b/source/forms/preferences/frmPreferences.cpp index 8157bbb..b9919c7 100644 --- a/source/forms/preferences/frmPreferences.cpp +++ b/source/forms/preferences/frmPreferences.cpp @@ -324,9 +324,7 @@ void frmPreferences::DeleteAccount( wxCommandEvent& event ) if (!accountDirFull.IsEmpty()){ - accountDirDelFull.Append(wxString::FromUTF8(getenv("HOME"))); - accountDirDelFull.Append(wxT("/.xestiacal/accounts/")); - accountDirDelFull.Append(accountDirFull); + accountDirDelFull.Append(GetAccountDir(accountDirFull, false)); DeleteDirectory(accountDirDelFull); diff --git a/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp b/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp index 5842631..5b24853 100644 --- a/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp +++ b/source/libraries/CalendarDataStorage/CalendarDataStorage.cpp @@ -986,9 +986,9 @@ CDSAddEntryResult CalendarDataStorage::AddEvent(int calendarID, std::string file // Load the event file. - CalendarEventObject eventData; + CalendarEventObject eventData; CalendarObjectLoadResult eventLoadResult = eventData.LoadFile(filename); - + // Check the result of the event file load. switch (eventLoadResult){ diff --git a/source/libraries/CalendarDataStorage/CalendarDataStorage.h b/source/libraries/CalendarDataStorage/CalendarDataStorage.h index 402aee8..1e934df 100644 --- a/source/libraries/CalendarDataStorage/CalendarDataStorage.h +++ b/source/libraries/CalendarDataStorage/CalendarDataStorage.h @@ -31,6 +31,10 @@ #include "../../common/colour.h" #include "../../common/random.h" +#if defined(WIN32) +#include +#endif + enum CDSAccountResult{ CDSACCOUNT_UNITTESTFAIL = -1, CDSACCOUNT_OK, diff --git a/source/objects/calendarlist/CalendarList.cpp b/source/objects/calendarlist/CalendarList.cpp index 8d4f1b5..403270c 100644 --- a/source/objects/calendarlist/CalendarList.cpp +++ b/source/objects/calendarlist/CalendarList.cpp @@ -46,13 +46,13 @@ XCAccountCalendarList::XCAccountCalendarList(string calendarListFilename){ calendarListFile->SetPath(accountName); - calendarShortName.push_back(string(accountName.mb_str())); + calendarShortName.push_back(string(accountName.ToUTF8())); calendarListFile->Read(wxT("name"), &valueData); - calendarName.push_back(string(valueData.mb_str())); + calendarName.push_back(string(valueData.ToUTF8())); calendarListFile->Read(wxT("description"), &valueData); - calendarDescription.push_back(string(valueData.mb_str())); + calendarDescription.push_back(string(valueData.ToUTF8())); calendarListFile->Read(wxT("colour"), &valueData); colourData = string(valueData.mb_str()); diff --git a/source/objects/calendarobject/CalendarObject-Save.cpp b/source/objects/calendarobject/CalendarObject-Save.cpp index 0cbe83e..0d72b46 100644 --- a/source/objects/calendarobject/CalendarObject-Save.cpp +++ b/source/objects/calendarobject/CalendarObject-Save.cpp @@ -28,7 +28,25 @@ CalendarObjectSaveResult CalendarObject::SaveFile(string saveFilename){ // Open the file. +#ifndef WIN32 + fileStream.open(saveFilename, ofstream::out); + +#else + + wstring saveFilename_utf16; + + int len = MultiByteToWideChar(CP_UTF8, 0, &saveFilename[0], (int)saveFilename.size(), NULL, 0); + + if (len > 0) + { + saveFilename_utf16.resize(len); + MultiByteToWideChar(CP_UTF8, 0, &saveFilename[0], (int)saveFilename.size(), &saveFilename_utf16[0], len); + } + + fileStream.open(saveFilename_utf16, ofstream::out); + +#endif if (fileStream.rdstate() & ofstream::failbit){ return CALENDAROBJECTSAVE_CANNOTOPEN; @@ -45,8 +63,10 @@ CalendarObjectSaveResult CalendarObject::SaveFile(string saveFilename){ saveResult = SaveString(&saveStringData); - fileStream.write(saveStringData.c_str(), saveStringData.size()); + //fileStream.write(saveStringData.c_str(), saveStringData.size()); + fileStream << saveStringData.c_str(); + fileStream.close(); return saveResult; diff --git a/source/objects/calendarobject/CalendarObject.cpp b/source/objects/calendarobject/CalendarObject.cpp index 6cfe78b..76cb4e6 100644 --- a/source/objects/calendarobject/CalendarObject.cpp +++ b/source/objects/calendarobject/CalendarObject.cpp @@ -26,15 +26,37 @@ CalendarObjectLoadResult CalendarObject::LoadFile(std::string loadFilename){ // Check if the file exists and return // CALENDAROBJECTLOAD_CANNOTOPEN if not. - if (!FileExists(loadFilename)){ - return CALENDAROBJECTLOAD_MISSING; - } - ifstream fileStream; string receivedStringData = ""; +#ifndef WIN32 + + if (!FileExists(loadFilename)) { + return CALENDAROBJECTLOAD_MISSING; + } + fileStream.open(loadFilename, ifstream::in); - + +#else + + wstring loadFilename_utf16; + + int len = MultiByteToWideChar(CP_UTF8, 0, &loadFilename[0], (int)loadFilename.size(), NULL, 0); + + if (len > 0) + { + loadFilename_utf16.resize(len); + MultiByteToWideChar(CP_UTF8, 0, &loadFilename[0], (int)loadFilename.size(), &loadFilename_utf16[0], len); + } + + if (!FileExists(loadFilename_utf16)) { + return CALENDAROBJECTLOAD_MISSING; + } + + fileStream.open(loadFilename_utf16, ifstream::in); + +#endif + if (fileStream.rdstate() & ifstream::failbit){ return CALENDAROBJECTLOAD_CANNOTOPEN; } diff --git a/source/objects/calendarobject/CalendarObject.h b/source/objects/calendarobject/CalendarObject.h index a99b796..1b03eee 100644 --- a/source/objects/calendarobject/CalendarObject.h +++ b/source/objects/calendarobject/CalendarObject.h @@ -30,6 +30,10 @@ #include "../../common/text.h" #include "../../version.h" +#if defined(WIN32) +#include +#endif + using namespace std; enum CalendarObjectLoadResult { diff --git a/source/widgets/XCCalendarDay.cpp b/source/widgets/XCCalendarDay.cpp index 656ad75..64bd1b4 100644 --- a/source/widgets/XCCalendarDay.cpp +++ b/source/widgets/XCCalendarDay.cpp @@ -524,7 +524,6 @@ void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){ this->Refresh(); mainPanel->Layout(); - eventListFrame->Layout(); eventListFrameSizer->Layout(); for (auto deleteIter : deleteEntriesList){ -- 2.39.2