Browse Source

Create ini file as unicode, this allows unicode string to be written and read from the ini file

Scott Brogden 9 years ago
parent
commit
7009d143a8
5 changed files with 73 additions and 39 deletions
  1. 2 2
      CP_Main.cpp
  2. 4 20
      DatabaseUtilities.cpp
  3. 9 4
      DittoSetup/BuildDitto.bld
  4. 57 13
      Options.cpp
  5. 1 0
      Options.h

+ 2 - 2
CP_Main.cpp

@@ -87,8 +87,6 @@ END_MESSAGE_MAP()
 
 CCP_MainApp::CCP_MainApp()
 {
-	theApp.m_activeWnd.TrackActiveWnd(false);
-
 	m_copyReason = CopyReasonEnum::COPY_TO_UNKOWN;
 	m_copyReasonStartTime = 0;
 	m_activeGroupId = -1;
@@ -155,6 +153,8 @@ BOOL CCP_MainApp::InitInstance()
 
 	g_Opt.LoadSettings();
 
+	theApp.m_activeWnd.TrackActiveWnd(false);
+
 	if(cmdInfo.m_uacPID > 0)
 	{
 		Log(StrF(_T("Startup up ditto as admin to paste to admin windows, parent process id: %d"), cmdInfo.m_uacPID));

+ 4 - 20
DatabaseUtilities.cpp

@@ -77,25 +77,7 @@ CString GetDefaultDBName()
 	}
 	else
 	{
-		LPMALLOC pMalloc;
-		
-		if(SUCCEEDED(::SHGetMalloc(&pMalloc))) 
-		{ 
-			LPITEMIDLIST pidlPrograms;
-				
-			SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlPrograms);
-				
-			TCHAR string[MAX_PATH];
-			SHGetPathFromIDList(pidlPrograms, string);
-				
-			pMalloc->Free(pidlPrograms);
-			pMalloc->Release();
-				
-			csDefaultPath = string;		
-		}
-
-		FIX_CSTRING_PATH(csDefaultPath);
-		csDefaultPath += "Ditto\\";
+		csDefaultPath = CGetSetOptions::GetAppDataPath();
 	}
 
 	CString csTempName = csDefaultPath + "Ditto.db";
@@ -117,7 +99,9 @@ BOOL CheckDBExists(CString csDBPath)
 	{
 		csDBPath = GetDefaultDBName();
 
-		if(FileExists(csDBPath) == FALSE && CGetSetOptions::GetIsPortableDitto() == FALSE)
+		if(FileExists(csDBPath) == FALSE && 
+			CGetSetOptions::GetIsPortableDitto() == FALSE &&
+			CGetSetOptions::GetIsWindowsApp() == FALSE)
 		{
 			CString csOldDB = CGetSetOptions::GetDBPathOld();
 			if(csOldDB.IsEmpty())

+ 9 - 4
DittoSetup/BuildDitto.bld

@@ -349,7 +349,8 @@ DittoSetup*]]></X>
 <Package
    xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
    xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
-   xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities">
+   xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
+   xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10">
   <Identity Name="Ditto"
     ProcessorArchitecture="x64"
     Publisher="CN=ScottBrogden, O=ScottBrogden, L=Ogallala, S=Nebraska, C=United States"
@@ -377,11 +378,15 @@ DittoSetup*]]></X>
        Square150x150Logo="Ditto_150.png"
        Square44x44Logo="Ditto_44.png"
        Description="Ditto" />
+       
+       <Extensions>
+			<desktop:Extension Category="windows.startupTask" Executable="Ditto.exe" EntryPoint="Windows.FullTrustApplication">
+				<desktop:StartupTask TaskId="DittoStartupTask" Enabled="true" DisplayName="Ditto Service" />
+			</desktop:Extension>
+		</Extensions>
+		
     </Application>
   </Applications>
-  <desktop:Extension Category="windows.startupTask" Executable="Ditto.exe" EntryPoint="Windows.FullTrustApplication">
-    <desktop:StartupTask TaskId="DittoStartupTask" Enabled="true" DisplayName="Ditto Service" />
-  </desktop:Extension>
 </Package>]]></Text>
 			<buildfailsteps type='11'>0</buildfailsteps>
 			<indent type='3'>2</indent>

+ 57 - 13
Options.cpp

@@ -1,4 +1,4 @@
-#include "stdafx.h"
+#include "stdafx.h"
 #include "Options.h"
 #include "AlphaBlend.h"
 #include "Misc.h"
@@ -122,6 +122,10 @@ void CGetSetOptions::LoadSettings()
 		CString csPath = GetFilePath(m_csIniFileName);
 		if(FileExists(csPath) == FALSE)
 			CreateDirectory(csPath, NULL);
+
+		//create the ini file as unicode, this way we can save unicode string to the ini file
+		//http://www.codeproject.com/Articles/9071/Using-Unicode-in-INI-files
+		CreateIniFile(m_csIniFileName);
 	}
 
 	/*CString cs = GetDBPath();
@@ -137,7 +141,7 @@ void CGetSetOptions::LoadSettings()
 	{
 		SetCheckForMaxEntries(TRUE);
 		SetSimpleTextSearch(TRUE);
-	}
+	}	
 
 	m_nLinesPerRow = GetLinesPerRow();
 	m_bUseCtrlNumAccel = GetUseCtrlNumForFirstTenHotKeys();
@@ -185,6 +189,24 @@ void CGetSetOptions::LoadSettings()
 	m_Theme.Load(GetTheme());
 }
 
+void CGetSetOptions::CreateIniFile(CString path)
+{
+	if (!::PathFileExists(path))
+	{
+		// UTF16-LE BOM(FFFE)
+		WORD wBOM = 0xFEFF;
+		DWORD NumberOfBytesWritten;
+
+		HANDLE hFile = ::CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
+		::WriteFile(hFile, &wBOM, sizeof(WORD), &NumberOfBytesWritten, NULL);
+	
+		//LPTSTR pszSectionB = _T("[StringTable]"); // section name with bracket 
+		//::WriteFile(hFile, pszSectionB, (_tcslen(pszSectionB) + 1)*(sizeof(TCHAR)), &NumberOfBytesWritten, NULL);
+
+		::CloseHandle(hFile);
+	}
+}
+
 void CGetSetOptions::ConverSettingsToIni()
 {
 	m_bInConversion = true;
@@ -309,22 +331,44 @@ CString CGetSetOptions::GetAppDataPath()
 	CString csPath;
 	LPMALLOC pMalloc;
 
-	if(SUCCEEDED(::SHGetMalloc(&pMalloc))) 
-	{ 
-		LPITEMIDLIST pidlPrograms;
+	if (GetIsWindowsApp())
+	{
+		if (SUCCEEDED(::SHGetMalloc(&pMalloc)))
+		{
+			LPITEMIDLIST pidlPrograms;
+
+			SHGetSpecialFolderLocation(NULL, CSIDL_LOCAL_APPDATA, &pidlPrograms);
 
-		SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlPrograms);
+			TCHAR string[MAX_PATH];
+			SHGetPathFromIDList(pidlPrograms, string);
 
-		TCHAR string[MAX_PATH];
-		SHGetPathFromIDList(pidlPrograms, string);
+			pMalloc->Free(pidlPrograms);
+			pMalloc->Release();
 
-		pMalloc->Free(pidlPrograms);
-		pMalloc->Release();
+			csPath = string;
+		}
+		FIX_CSTRING_PATH(csPath);
+		csPath += "Ditto_WindowsApp\\";
+	}
+	else
+	{
+		if (SUCCEEDED(::SHGetMalloc(&pMalloc)))
+		{
+			LPITEMIDLIST pidlPrograms;
+
+			SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidlPrograms);
+
+			TCHAR string[MAX_PATH];
+			SHGetPathFromIDList(pidlPrograms, string);
 
-		csPath = string;		
+			pMalloc->Free(pidlPrograms);
+			pMalloc->Release();
+
+			csPath = string;
+		}
+		FIX_CSTRING_PATH(csPath);
+		csPath += "Ditto\\";
 	}
-	FIX_CSTRING_PATH(csPath);
-	csPath += "Ditto\\";
 
 	return csPath;
 }

+ 1 - 0
Options.h

@@ -80,6 +80,7 @@ public:
 	static void ConverSettingsToIni();
 	static CString GetAppDataPath();
 	static CString GetTempFilePath();
+	static void CreateIniFile(CString path);
 
 	static CString GetExeFileName();
 	static CString GetAppName();