瀏覽代碼

added support for a portable version, all settings are local

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@388 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 18 年之前
父節點
當前提交
f0b5083fce
共有 3 個文件被更改,包括 88 次插入49 次删除
  1. 25 18
      DatabaseUtilities.cpp
  2. 58 30
      Options.cpp
  3. 5 1
      Options.h

+ 25 - 18
DatabaseUtilities.cpp

@@ -74,25 +74,32 @@ 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;		
+		if(CGetSetOptions::GetIsPortableDitto())
+		{
+			csDefaultPath.Empty();
 		}
+		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\\";
+			FIX_CSTRING_PATH(csDefaultPath);
+			csDefaultPath += "Ditto\\";
+		}
 	}
 
 	if(FileExists(csDefaultPath) == FALSE)
@@ -117,7 +124,7 @@ BOOL CheckDBExists(CString csDBPath)
 	{
 		csDBPath = GetDefaultDBName();
 
-		if(FileExists(csDBPath) == FALSE)
+		if(FileExists(csDBPath) == FALSE && CGetSetOptions::GetIsPortableDitto() == FALSE)
 		{
 			CString csOldDB = CGetSetOptions::GetDBPathOld();
 			if(csOldDB.IsEmpty())

+ 58 - 30
Options.cpp

@@ -75,29 +75,32 @@ CGetSetOptions::~CGetSetOptions()
 
 void CGetSetOptions::LoadSettings()
 {
-	m_csIniFileName = GetIniFileName();
+	m_csIniFileName = GetIniFileName(false);
 
 	if(m_bU3)
+	{
 		m_bFromIni = true;
-
-	if(!m_bU3)
+	}
+	else
 	{
-//		m_bInConversion = true;
-//
-//		//If there is a variable in the registry for the db path but no .ini file
-//		//then we need to convert the registry settings to .ini settings
-//
-//		CString csDB = GetDBPath();
-//		if(csDB.IsEmpty())
-//			csDB = GetDBPathOld();
-//		if(csDB.IsEmpty() == FALSE && FileExists(m_csIniFileName) == FALSE)
-//		{
-//			ConverSettingsToIni();
-//		}
-//
-//		m_bInConversion = false;
+		//First check to see if they have an ini file in my docs&settings - ditto
+		if(FileExists(m_csIniFileName))
+		{
+			m_bFromIni = true;
+		}
+		else
+		{
+			//next check if they have an ini file in the application directory
+			m_csIniFileName = GetIniFileName(true);
+			if(FileExists(m_csIniFileName))
+			{
+				m_bFromIni = true;
+			}
+		}
 	}
 
+	GetSetCurrentDirectory();
+
 	m_nLinesPerRow = GetLinesPerRow();
 	m_bUseCtrlNumAccel = GetUseCtrlNumForFirstTenHotKeys();
 	m_bAllowDuplicates = GetAllowDuplicates();
@@ -292,7 +295,7 @@ void CGetSetOptions::ConverSettingsToIni()
 	m_bInConversion = false;
 }
 
-CString CGetSetOptions::GetIniFileName()
+CString CGetSetOptions::GetIniFileName(bool bLocalIniFile)
 {
 	CString csPath = _T("c:\\program files\\Ditto\\");
 
@@ -302,24 +305,31 @@ CString CGetSetOptions::GetIniFileName()
 	}
 	else
 	{	
-		LPMALLOC pMalloc;
+		if(bLocalIniFile)
+		{
+			csPath = GetFilePath(GetExeFileName());
+		}
+		else
+		{
+			LPMALLOC pMalloc;
 
-		if(SUCCEEDED(::SHGetMalloc(&pMalloc))) 
-		{ 
-			LPITEMIDLIST pidlPrograms;
+			if(SUCCEEDED(::SHGetMalloc(&pMalloc))) 
+			{ 
+				LPITEMIDLIST pidlPrograms;
 
-			SHGetSpecialFolderLocation(NULL, CSIDL_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;		
+				csPath = string;		
+			}
+			FIX_CSTRING_PATH(csPath);
+			csPath += "Ditto\\";
 		}
-		FIX_CSTRING_PATH(csPath);
-		csPath += "Ditto\\";
 	}
 
 	if(FileExists(csPath) == FALSE)
@@ -1687,4 +1697,22 @@ CString CGetSetOptions::GetMultiPasteSeparator(bool bConvertToLineFeeds)
 void CGetSetOptions::SetMultiPasteSeparator(CString csSep)
 {
 	SetProfileString(_T("MultiPasteSeparator"), csSep);
+}
+
+BOOL CGetSetOptions::GetSetCurrentDirectory()
+{
+	BOOL bRet = GetProfileLong(_T("SetCurrentDirectory"), FALSE);
+	if(bRet)
+	{
+		CString csExePath = GetFilePath(GetExeFileName());
+		FIX_CSTRING_PATH(csExePath);
+		::SetCurrentDirectory(csExePath);
+	}
+
+	return bRet;
+}
+
+bool CGetSetOptions::GetIsPortableDitto()
+{
+	return GetProfileLong(_T("Portable"), FALSE) == TRUE;
 }

+ 5 - 1
Options.h

@@ -68,7 +68,7 @@ public:
 	static bool m_bU3;
 
 	static void LoadSettings();
-	static CString GetIniFileName();
+	static CString GetIniFileName(bool bLocalIniFile);
 	static void ConverSettingsToIni();
 
 	static CString GetExeFileName();
@@ -349,6 +349,10 @@ public:
 
 	static CString  GetMultiPasteSeparator(bool bConvertToLineFeeds = true);
 	static void		SetMultiPasteSeparator(CString csSep);
+
+	static BOOL		GetSetCurrentDirectory();
+
+	static bool		GetIsPortableDitto();
 };
 
 // global for easy access and for initialization of fast access variables