CString GetDefaultDBName() { CString csDefaultPath = _T("c:\\program files\\Ditto\\"); if(g_Opt.m_bU3) { csDefaultPath = CGetSetOptions::GetPath(PATH_DATABASE); } else { //If portable then default to the running path 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\\"; } } CString csTempName = csDefaultPath + "Ditto.db"; int i = 1; while(FileExists(csTempName)) { csTempName.Format(_T("%sDitto_%d.db"), csDefaultPath, i); i++; } csDefaultPath = csTempName; return csDefaultPath; }
void DeleteReceivedFiles(CString csDir) { if(csDir.Find(_T("\\ReceivedFiles\\")) == -1) return; FIX_CSTRING_PATH(csDir); CTime ctOld = CTime::GetCurrentTime(); CTime ctFile; ctOld -= CTimeSpan(0, 0, 0, 1); CFileFind Find; CString csFindString; csFindString.Format(_T("%s*.*"), csDir); BOOL bFound = Find.FindFile(csFindString); while(bFound) { bFound = Find.FindNextFile(); if(Find.IsDots()) continue; if(Find.IsDirectory()) { CString csDir(Find.GetFilePath()); DeleteReceivedFiles(csDir); RemoveDirectory(csDir); } if(Find.GetLastAccessTime(ctFile)) { //Delete the remote copied file if it has'nt been used for the last day if(ctFile < ctOld) { DeleteFile(Find.GetFilePath()); } } else { DeleteFile(Find.GetFilePath()); } } }