Просмотр исходного кода

Use system temp path for drag file / remote files / compare files. user app data was causing issues when running as windows store app

Scott Brogden 9 лет назад
Родитель
Сommit
06382ce474
8 измененных файлов с 99 добавлено и 118 удалено
  1. 4 0
      CP_Main.cpp
  2. 21 24
      ClipCompare.cpp
  3. 1 1
      MainFrm.cpp
  4. 1 11
      MainFrmThread.cpp
  5. 31 7
      Misc.cpp
  6. 2 1
      Misc.h
  7. 38 74
      Options.cpp
  8. 1 0
      Options.h

+ 4 - 0
CP_Main.cpp

@@ -166,6 +166,8 @@ BOOL CCP_MainApp::InitInstance()
 	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
 	Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
 
+	//MessageBox(NULL, _T("ditto starting"), _T("d"), MB_OK);
+
 	DittoCommandLineInfo cmdInfo;
 	ParseCommandLine(cmdInfo);
 
@@ -870,6 +872,8 @@ int CCP_MainApp::ExitInstance()
 {
 	Log(_T("ExitInstance"));
 
+	DeleteDittoTempFiles(FALSE);
+
 	m_db.close();
 
 	if(m_pUacPasteThread != NULL)

+ 21 - 24
ClipCompare.cpp

@@ -124,34 +124,31 @@ CString CClipCompare::GetComparePath()
 CString CClipCompare::SaveToFile(int id, CClip *pClip, bool saveW, bool SaveA)
 {
 	CString path;
-	wchar_t wchPath[MAX_PATH];
-	if (GetTempPathW(MAX_PATH, wchPath))
-	{
-		CString cs;
-		cs.Format(_T("%sditto_compare_%d.txt"), wchPath, id);
+	CString pathCompare = CGetSetOptions::GetPath(PATH_CLIP_DIFF);
+	CString cs;
+	cs.Format(_T("%sditto_compare_%d.txt"), pathCompare, id);
 
-		if(FileExists(cs))
-		{
-			for(int i = 0; i < 1000; i++)
-			{			
-				cs.Format(_T("%sditto_compare_%d.txt"), wchPath, id);
-				if(FileExists(cs))
-				{
-					path = cs;
-					break;
-				}
+	if(FileExists(cs))
+	{
+		for(int i = 0; i < 1000; i++)
+		{			
+			cs.Format(_T("%sditto_compare_%d.txt"), pathCompare, id);
+			if(FileExists(cs))
+			{
+				path = cs;
+				break;
 			}
 		}
-		else
-		{
-			path = cs;
-		}
+	}
+	else
+	{
+		path = cs;
+	}
 
-		if(path != _T("") && 
-			pClip != NULL)
-		{
-			pClip->WriteTextToFile(path, saveW, SaveA, false);
-		}
+	if(path != _T("") && 
+		pClip != NULL)
+	{
+		pClip->WriteTextToFile(path, saveW, SaveA, false);
 	}
 
 	return path;

+ 1 - 1
MainFrm.cpp

@@ -148,7 +148,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
     #endif 
 
     //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR*24, 0);
-	SetTimer(REMOVE_OLD_TEMP_FILES, ONE_DAY, 0);
+	SetTimer(REMOVE_OLD_TEMP_FILES, ONE_HOUR * 6, 0);
     SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE*15, 0);
 
 	//found on some computers GetTickCount gettickcount returns a smaller value than other, can't explain

+ 1 - 11
MainFrmThread.cpp

@@ -103,17 +103,7 @@ void CMainFrmThread::OnDeleteEntries()
 
 void CMainFrmThread::OnRemoveTempFiles()
 {
-    CString csDir = CGetSetOptions::GetPath(PATH_REMOTE_FILES);
-    if(FileExists(csDir))
-    {
-        DeleteReceivedFiles(csDir);
-    }
-
-	csDir = CGetSetOptions::GetPath(PATH_DRAG_FILES);
-	if (FileExists(csDir))
-	{
-		DeleteReceivedFiles(csDir);
-	}
+	DeleteDittoTempFiles(TRUE);
 }
 
 void CMainFrmThread::OnSaveClips()

+ 31 - 7
Misc.cpp

@@ -961,11 +961,34 @@ bool IsRunningLimited()
 	return false;
 }
 
-void DeleteReceivedFiles(CString csDir)
+void DeleteDittoTempFiles(BOOL checkFileLastAccess)
 {
-	if (csDir.Find(_T("\\ReceivedFiles\\")) == -1 && csDir.Find(_T("\\DragFiles\\")) == -1)
+	CString csDir = CGetSetOptions::GetPath(PATH_REMOTE_FILES);
+	if (FileExists(csDir))
+	{
+		DeleteFolderFiles(csDir, checkFileLastAccess);
+	}
+
+	csDir = CGetSetOptions::GetPath(PATH_DRAG_FILES);
+	if (FileExists(csDir))
+	{
+		DeleteFolderFiles(csDir, checkFileLastAccess);
+	}
+
+	csDir = CGetSetOptions::GetPath(PATH_CLIP_DIFF);
+	if (FileExists(csDir))
+	{
+		DeleteFolderFiles(csDir, checkFileLastAccess);
+	}
+}
+
+void DeleteFolderFiles(CString csDir, BOOL checkFileLastAccess)
+{
+	if (csDir.Find(_T("\\ReceivedFiles\\")) == -1 && csDir.Find(_T("\\DragFiles\\")) == -1 && csDir.Find(_T("ClipCompare")) == -1)
 		return;
 
+	Log(StrF(_T("Deleting files in Folder %s Check Last Access %d"), csDir, checkFileLastAccess));
+
 	FIX_CSTRING_PATH(csDir);
 
 	CTime ctOld = CTime::GetCurrentTime();
@@ -988,20 +1011,23 @@ void DeleteReceivedFiles(CString csDir)
 		if(Find.IsDirectory())
 		{
 			CString csDir(Find.GetFilePath());
-			DeleteReceivedFiles(csDir);
+			DeleteFolderFiles(csDir, checkFileLastAccess);
 			RemoveDirectory(csDir);
 		}
 
-		if(Find.GetLastAccessTime(ctFile))
+		if(checkFileLastAccess &&
+			Find.GetLastAccessTime(ctFile))
 		{
-			//Delete the remote copied file if it has'nt been used for the last day
+			//Delete the remote copied file if it hasn't been used for the last day
 			if(ctFile < ctOld)
 			{
+				Log(StrF(_T("Deleting temp file %s"), Find.GetFilePath()));
 				DeleteFile(Find.GetFilePath());
 			}
 		}
 		else
 		{
+			Log(StrF(_T("Deleting temp file %s"), Find.GetFilePath()));
 			DeleteFile(Find.GetFilePath());
 		}
 	}
@@ -1016,8 +1042,6 @@ __int64 FileSize(const TCHAR *fileName)
 	return buf.st_size;
 }
 
-
-
 int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert)
 {
 	int replaceCount = 0;

+ 2 - 1
Misc.h

@@ -167,7 +167,8 @@ __inline BOOL FileExists(LPCTSTR pszFile)
 bool IsRunningLimited();
 BOOL IsVista();
 
-void DeleteReceivedFiles(CString csDir);
+void DeleteDittoTempFiles(BOOL checkFileLastAccess);
+void DeleteFolderFiles(CString csDir, BOOL checkFileLastAccess);
 
 __int64 FileSize(const TCHAR *fileName);
 

+ 38 - 74
Options.cpp

@@ -116,6 +116,11 @@ void CGetSetOptions::LoadSettings()
 			CreateDirectory(csPath, NULL);
 	}
 
+	/*CString cs = GetDBPath();
+	SetDBPath(_T("some path"));
+	CString cs2 = GetDBPath();*/
+
+
 	GetSetCurrentDirectory();
 
 	//First time we run, set some defaults
@@ -1638,62 +1643,19 @@ CString CGetSetOptions::GetPath(long lPathID)
 	switch(lPathID)
 	{
 	case PATH_HELP:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_DEVICE_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
-
 		csDir += "Help\\";
 		break;
 	
 	case PATH_LANGUAGE:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_DEVICE_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
-
 		csDir += "language\\";
-
 		break;
 
 	case PATH_THEMES:
-
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_DEVICE_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
-
 		csDir += "Themes\\";
-
-		break;
-
-	case PATH_REMOTE_FILES:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_HOST_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
-		else if(CGetSetOptions::GetIsPortableDitto() == false)
-		{
-			csDir = GetAppDataPath();
-		}
-
-		csDir += "ReceivedFiles\\";
 		break;
 
-	case PATH_LOG_FILE:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_HOST_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
-		else if(CGetSetOptions::GetIsPortableDitto() == false)
-		{
-			csDir = GetAppDataPath();
-		}
+	case PATH_LOG_FILE:if(CGetSetOptions::GetIsPortableDitto() == false)
+		csDir = GetAppDataPath();		
 
 		break;
 
@@ -1702,53 +1664,55 @@ CString CGetSetOptions::GetPath(long lPathID)
 		break;
 
 	case PATH_DATABASE:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_APP_DATA_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
 		break;
 
-
 	case PATH_INI:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_APP_DATA_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
 		break;
 
 	case PATH_U3_HWND_INI:
-		if(m_bU3)
-		{
-			csDir = GETENV(_T("U3_HOST_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
-		}
 		break;
 
 	case PATH_ADDINS:
-		if(m_bU3)
+		csDir += "Addins\\";		
+		break;
+
+	case PATH_REMOTE_FILES:
+		if (CGetSetOptions::GetIsPortableDitto() == false)
 		{
-			csDir = GETENV(_T("U3_DEVICE_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
+			wchar_t wchPath[MAX_PATH];
+			if (GetTempPathW(MAX_PATH, wchPath))
+			{
+				csDir = wchPath;
+				csDir += _T("Ditto\\");
+			}
 		}
-
-		csDir += "Addins\\";
-		
+		csDir += "ReceivedFiles\\";
 		break;
 
 	case PATH_DRAG_FILES:
-		if (m_bU3)
+		if (CGetSetOptions::GetIsPortableDitto() == false)
 		{
-			csDir = GETENV(_T("U3_HOST_EXEC_PATH"));
-			FIX_CSTRING_PATH(csDir);
+			wchar_t wchPath[MAX_PATH];
+			if (GetTempPathW(MAX_PATH, wchPath))
+			{
+				csDir = wchPath;
+				csDir += _T("Ditto\\");
+			}
 		}
-		else if (CGetSetOptions::GetIsPortableDitto() == false)
+		csDir += "DragFiles\\";
+		break;
+
+	case PATH_CLIP_DIFF:
+		if (CGetSetOptions::GetIsPortableDitto() == false)
 		{
-			csDir = GetAppDataPath();
+			wchar_t wchPath[MAX_PATH];
+			if (GetTempPathW(MAX_PATH, wchPath))
+			{
+				csDir = wchPath;	
+				csDir += _T("Ditto\\");
+			}
 		}
-
-		csDir += "DragFiles\\";
+		csDir += _T("ClipCompare\\");
 		break;
 
 	}

+ 1 - 0
Options.h

@@ -60,6 +60,7 @@ public:
 #define PATH_THEMES			8
 #define PATH_ADDINS			9
 #define PATH_DRAG_FILES		10
+#define PATH_CLIP_DIFF		11
 
 class CGetSetOptions
 {