sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory) { rtl_uString *ustrSysDir = NULL; sal_Bool bSuccess = sal_False; if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; if (pSecImpl->m_pNetResource != NULL) { rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory )); } else { bSuccess = (sal_Bool)(GetSpecialFolder(&ustrSysDir, CSIDL_PERSONAL) && (osl_File_E_None == osl_getFileURLFromSystemPath(ustrSysDir, pustrDirectory))); } } if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); return bSuccess; }
/* Return false if this program has been started from "Program Files" directory (which is an indicator that it has been installed) or from the last known location of a SumatraPDF installation: */ bool IsRunningInPortableMode() { // cache the result so that it will be consistent during the lifetime of the process static int sCacheIsPortable = -1; // -1 == uninitialized, 0 == installed, 1 == portable if (sCacheIsPortable != -1) return sCacheIsPortable != 0; sCacheIsPortable = 1; if (HasBeenInstalled()) { sCacheIsPortable = 0; return false; } ScopedMem<WCHAR> exePath(GetExePath()); ScopedMem<WCHAR> programFilesDir(GetSpecialFolder(CSIDL_PROGRAM_FILES)); // if we can't get a path, assume we're not running from "Program Files" if (!exePath || !programFilesDir) return true; // check if one of the exePath's parent directories is "Program Files" // (or a junction to it) WCHAR *baseName; while ((baseName = (WCHAR*)path::GetBaseName(exePath)) > exePath) { baseName[-1] = '\0'; if (path::IsSame(programFilesDir, exePath)) { sCacheIsPortable = 0; return false; } } return true; }
sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory) { rtl_uString *ustrSysDir = NULL; sal_Bool bSuccess = sal_False; if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; if (pSecImpl->m_pNetResource != NULL) { rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory )); } else { #if 0 if (pSecImpl->m_hToken) { DWORD nInfoBuffer = 512; UCHAR* pInfoBuffer = malloc(nInfoBuffer); while (!GetTokenInformation(pSecImpl->m_hToken, TokenUser, pInfoBuffer, nInfoBuffer, &nInfoBuffer)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer); else { free(pInfoBuffer); pInfoBuffer = NULL; break; } } /* not implemented */ OSL_ASSERT(sal_False); if (pInfoBuffer) { /* if (EqualSid() ... */ } } else #endif bSuccess = (sal_Bool)(GetSpecialFolder(&ustrSysDir, CSIDL_PERSONAL) && (osl_File_E_None == osl_getFileURLFromSystemPath(ustrSysDir, pustrDirectory))); } } if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); return bSuccess; }
/* #FN# Gets a path to 'Desktop' folder */ void /* #AS# Nothing */ CWizardStep1:: GetDeskFolder( LPSTR szDeskPath /* #OUT# Path to the requested desktop object */ ) { GetSpecialFolder( CSIDL_DESKTOP, szDeskPath ); } /* #OF# CWizardStep1::GetDeskFolder */
/* #FN# Gets a path to the emulator folder located in 'Programs' menu */ void /* #AS# Nothing */ CWizardStep1:: GetMenuFolder( LPSTR szMenuPath /* #OUT# Path to the requested menu object */ ) { GetSpecialFolder( CSIDL_PROGRAMS, szMenuPath ); strcat( szMenuPath, "\\Atari800Win PLus" ); } /* #OF# CWizardStep1::GetMenuFolder */
bool CSVNStatusCache::SaveCache() { #define WRITEVALUETOFILE(x) if (fwrite(&x, sizeof(x), 1, pFile)!=1) goto error; unsigned int value = 0; // save the cache to disk FILE * pFile = NULL; // find a location to write the cache to CString path = GetSpecialFolder(FOLDERID_LocalAppData); if (!path.IsEmpty()) { path += L"\\TSVNCache"; if (!PathIsDirectory(path)) CreateDirectory(path, NULL); path += STATUSCACHEFILENAME; _tfopen_s(&pFile, path, L"wb"); if (pFile) { value = CACHEDISKVERSION; // 'version' WRITEVALUETOFILE(value); value = (int)m_pInstance->m_directoryCache.size(); WRITEVALUETOFILE(value); for (CCachedDirectory::CachedDirMap::iterator I = m_pInstance->m_directoryCache.begin(); I != m_pInstance->m_directoryCache.end(); ++I) { if (I->second == NULL) { value = 0; WRITEVALUETOFILE(value); continue; } const CString& key = I->first.GetWinPathString(); value = key.GetLength(); WRITEVALUETOFILE(value); if (value) { if (fwrite((LPCTSTR)key, sizeof(TCHAR), value, pFile)!=value) goto error; if (!I->second->SaveToDisk(pFile)) goto error; } } fclose(pFile); } } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": cache saved to disk at %s\n", path); return true; error: fclose(pFile); Destroy(); DeleteFile(path); return false; }
CSVNStatusCache::CSVNStatusCache(void) { #define forever DWORD(-1) AutoLocker lock(m_NoWatchPathCritSec); m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_Cookies))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_History))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_InternetCache))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_Windows))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_CDBurning))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_Fonts))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_RecycleBinFolder))] = forever; m_NoWatchPaths[CTSVNPath(GetSpecialFolder(FOLDERID_SearchHistory))] = forever; m_bClearMemory = false; m_mostRecentExpiresAt = 0; }
bool CLocalTreeView::CreateRoot() { int iconIndex, openIconIndex; wxString name = GetSpecialFolder(CSIDL_DESKTOP, iconIndex, openIconIndex); if (name == _T("")) { name = _("Desktop"); iconIndex = openIconIndex = -1; } m_desktop = AddRoot(name, iconIndex, openIconIndex); name = GetSpecialFolder(CSIDL_PERSONAL, iconIndex, openIconIndex); if (name == _T("")) { name = _("My Documents"); iconIndex = openIconIndex = -1; } m_documents = AppendItem(m_desktop, name, iconIndex, openIconIndex); name = GetSpecialFolder(CSIDL_DRIVES, iconIndex, openIconIndex); if (name == _T("")) { name = _("My Computer"); iconIndex = openIconIndex = -1; } m_drives = AppendItem(m_desktop, name, iconIndex, openIconIndex); DisplayDrives(m_drives); Expand(m_desktop); Expand(m_drives); return true; }
/* Caller needs to free() the result. */ WCHAR *AppGenDataFilename(const WCHAR *fileName) { ScopedMem<WCHAR> path; /* Use %APPDATA% */ path.Set(GetSpecialFolder(CSIDL_APPDATA, true)); if (path) { path.Set(path::Join(path, APP_NAME_STR)); if (path && !dir::Create(path)) path.Set(NULL); } if (!path || !fileName) return NULL; return path::Join(path, fileName); }
sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDirectory) { sal_Bool bSuccess = sal_False; if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; if (pSecImpl->m_pNetResource != NULL) { rtl_uString *ustrSysDir = NULL; rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory)); if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); } else { if (pSecImpl->m_hToken) { /* not implemented */ OSL_ASSERT(sal_False); } else { rtl_uString *ustrFile = NULL; sal_Unicode sFile[_MAX_PATH]; if ( !GetSpecialFolder( &ustrFile, CSIDL_APPDATA) ) { OSL_VERIFY(GetWindowsDirectoryW(sFile, _MAX_DIR) > 0); rtl_uString_newFromStr( &ustrFile, sFile); } bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath(ustrFile, pustrDirectory)); if ( ustrFile ) rtl_uString_release( ustrFile ); } } } return bSuccess; }
/********************************************* This routine tests if a link already exists: *********************************************/ BOOL CShortcut::isLinkExist(const CString &LnkName, UINT SpecialFolder) const { CFileStatus cfStatus; CString sSpecialFolder; // Find the Special Folder: if (!GetSpecialFolder(SpecialFolder, sSpecialFolder)) return FALSE; // Work with the special folder's path (contained in szPath) sSpecialFolder += L"\\"; sSpecialFolder += LnkName + L"." + L"lnk"; BOOL brc = CFile::GetStatus(sSpecialFolder, cfStatus); pws_os::Trace(L"%s = %s\n", brc == TRUE ? L"Full file name" : L"File NOT available", cfStatus.m_szFullName); return brc; }
bool IsRunningInPortableMode() { // cache the result so that it will be consistent during the lifetime of the process static int sCacheIsPortable = -1; // -1 == uninitialized, 0 == installed, 1 == portable if (sCacheIsPortable != -1) return sCacheIsPortable != 0; sCacheIsPortable = 1; ScopedMem<WCHAR> exePath(GetExePath()); if (!exePath) return true; // if we can't get a path, assume we're not running from "Program Files" ScopedMem<WCHAR> installedPath; // cf. GetInstallationDir() in installer\Installer.cpp installedPath.Set(ReadRegStr(HKEY_CURRENT_USER, REG_PATH_UNINST, L"InstallLocation")); if (!installedPath) installedPath.Set(ReadRegStr(HKEY_LOCAL_MACHINE, REG_PATH_UNINST, L"InstallLocation")); if (installedPath) { if (!str::EndsWithI(installedPath.Get(), L".exe")) installedPath.Set(path::Join(installedPath.Get(), path::GetBaseName(exePath))); if (path::IsSame(installedPath, exePath)) { sCacheIsPortable = 0; return false; } } ScopedMem<WCHAR> programFilesDir(GetSpecialFolder(CSIDL_PROGRAM_FILES)); if (!programFilesDir) return true; // check if one of the exePath's parent directories is "Program Files" // (or a junction to it) WCHAR *baseName; while ((baseName = (WCHAR*)path::GetBaseName(exePath)) > exePath) { baseName[-1] = '\0'; if (path::IsSame(programFilesDir, exePath)) { sCacheIsPortable = 0; return false; } } return true; }
BOOL CShortcut::DeleteShortCut(const CString &LnkName, UINT SpecialFolder) { CFile cfFull; CString sExePath, sExe, sSpecialFolder; wchar_t *chTmp = sExePath.GetBuffer(MAX_PATH); GetModuleFileName(NULL, chTmp, MAX_PATH); sExePath.ReleaseBuffer(); if (!GetSpecialFolder(SpecialFolder, sSpecialFolder)) return FALSE; // Work with the special folder's path (contained in szPath) cfFull.SetFilePath(sExePath); sExe = cfFull.GetFileName(); sExe.Delete(sExe.Find(L".") + 1, 3); sSpecialFolder += LnkName + L"." + L"lnk"; // DELETE THE LINK: SHFILEOPSTRUCT FIO = {0}; // FIO.pTo=NULL; // MUST be NULL FIO.wFunc = FO_DELETE; FIO.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION; if (sSpecialFolder.Find(L'\0') != sSpecialFolder.GetLength()) { FIO.fFlags |= FOF_MULTIDESTFILES; } if (sSpecialFolder.Right(1)) { sSpecialFolder += L'\0'; } FIO.pFrom = &*sSpecialFolder; int bD = SHFileOperation(&FIO); if (!bD) { pws_os::Trace(L"Lnk Deleted!\n"); return TRUE; } else { pws_os::Trace(L"Lnk NOT Deleted! DeleteShortCut(...) FAILED!\n"); return FALSE; } }
void SelectTranslation(const WCHAR *exePath=NULL) { LANGID langId = GetUserDefaultUILanguage(); int idx = GetLanguageIndex(langId); if (-1 == idx) { // try a neutral language if the specific sublanguage isn't available langId = MAKELANGID(PRIMARYLANGID(langId), SUBLANG_NEUTRAL); idx = GetLanguageIndex(langId); } if (-1 != idx) { gTranslationIdx = idx; plogf("sp: Detected language %s (%d)", gLanguages[idx / gTranslationsCount], idx); } // try to extract the language used by SumatraPDF ScopedMem<WCHAR> path; if (exePath) { path.Set(path::GetDir(exePath)); path.Set(path::Join(path, PREFS_FILE_NAME)); } if (!file::Exists(path)) { path.Set(GetSpecialFolder(CSIDL_APPDATA)); path.Set(path::Join(path, L"SumatraPDF\\" PREFS_FILE_NAME)); } if (!file::Exists(path)) return; plogf("sp: Found preferences at %S", path); ScopedMem<char> prefsData(file::ReadAll(path, NULL)); SquareTree sqt(prefsData); const char *langCode = sqt.root ? sqt.root->GetValue("UiLanguage") : NULL; if (langCode) { plogf("sp: UiLanguage from preferences: %s", langCode); for (int i = 0; gLanguages[i]; i++) { if (str::Eq(gLanguages[i], langCode)) { gTranslationIdx = i * gTranslationsCount; break; } } } }
/* Caller needs to free() the result. */ WCHAR *AppGenDataFilename(const WCHAR *fileName) { ScopedMem<WCHAR> path; if (IsRunningInPortableMode()) { /* Use the same path as the binary */ ScopedMem<WCHAR> exePath(GetExePath()); if (exePath) path.Set(path::GetDir(exePath)); } else { /* Use %APPDATA% */ path.Set(GetSpecialFolder(CSIDL_APPDATA, true)); if (path) { path.Set(path::Join(path, APP_NAME_STR)); if (path && !dir::Create(path)) path.Set(NULL); } } if (!path || !fileName) return NULL; return path::Join(path, fileName); }
/* Caller needs to free() the result. */ WCHAR *AppGenDataFilename(const WCHAR *fileName) { if (!fileName) return nullptr; if (gAppDataPath && dir::Exists(gAppDataPath)) { return path::Join(gAppDataPath, fileName); } if (IsRunningInPortableMode()) { /* Use the same path as the binary */ return path::GetAppPath(fileName); } /* Use %APPDATA% */ ScopedMem<WCHAR> path(GetSpecialFolder(CSIDL_APPDATA, true)); if (!path) return nullptr; path.Set(path::Join(path, APP_NAME_STR)); if (!path || !dir::Create(path)) return nullptr; return path::Join(path, fileName); }
void SelectTranslation(const WCHAR *exePath=NULL) { LANGID langId = GetUserDefaultUILanguage(); int idx = GetLanguageIndex(langId); if (-1 == idx) { // try a neutral language if the specific sublanguage isn't available langId = MAKELANGID(PRIMARYLANGID(langId), SUBLANG_NEUTRAL); idx = GetLanguageIndex(langId); } if (-1 != idx) { gTranslationIdx = idx; plogf("sp: Detected language %s (%d)", gLanguages[idx / gTranslationsCount], idx); } // try to extract the language used by SumatraPDF ScopedMem<WCHAR> path; if (exePath) { path.Set(path::GetDir(exePath)); path.Set(path::Join(path, PREFS_FILE_NAME)); } if (!file::Exists(path)) { path.Set(GetSpecialFolder(CSIDL_APPDATA)); path.Set(path::Join(path, L"SumatraPDF\\" PREFS_FILE_NAME)); } if (!file::Exists(path)) return; plogf("sp: Found preferences at %S", path); #ifndef USE_INI_SETTINGS ScopedMem<char> data(file::ReadAll(path, NULL)); if (data) { BencObj *root = BencObj::Decode(data); if (root && root->Type() == BT_DICT) { BencDict *global = static_cast<BencDict *>(root)->GetDict("gp"); BencString *string = global ? global->GetString("UILanguage") : NULL; if (string) { plogf("sp: UILanguage from preferences: %s", string->RawValue()); for (int i = 0; gLanguages[i]; i++) { if (str::Eq(gLanguages[i], string->RawValue())) { gTranslationIdx = i * gTranslationsCount; break; } } } } delete root; } #else IniFile ini(path); IniSection *section = ini.FindSection(NULL); IniLine *line = section ? section->FindLine("CurrLangCode") : NULL; if (line) { plogf("sp: UILanguage from preferences: %s", line->value); for (int i = 0; gLanguages[i]; i++) { if (str::Eq(gLanguages[i], line->value)) { gTranslationIdx = i * gTranslationsCount; break; } } } #endif }
/********************************************* This routine resolves the lnk destination: \param LnkName - The name of the ShortCut\n \param SpecialFolder - where to put the shortcut (See #defines above (MSDN)) \param hwnd - handle of the parent window for MessageBoxes the shell may need to display \param LnkPath - Reference to a CString that receives the linkpath if routine is successful else the string will be empty \param LnkDescription - Reference to a CString that receives the Description of the link else the string will be empty \returns a HRESULT *********************************************/ HRESULT CShortcut::ResolveLink(const CString &LnkName, UINT SpecialFolder, HWND hwnd, CString &LnkPath, CString &LnkDescription) { HRESULT hres; IShellLink* psl; wchar_t *szGotPath = LnkPath.GetBuffer(MAX_PATH); wchar_t *szDescription = LnkDescription.GetBuffer(MAX_PATH); CString sLnkFile, sSpecialFolder; CString sLong; WIN32_FIND_DATA wfd; // get the path to the special folder: if (!GetSpecialFolder(SpecialFolder, sSpecialFolder)) return 1; // return ERROR // build a linkfile: sLnkFile = sSpecialFolder + LnkName + L".lnk"; // Get a pointer to the IShellLink interface. hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl); if (SUCCEEDED(hres)) { IPersistFile* ppf; // Get a pointer to the IPersistFile interface. hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf); if (SUCCEEDED(hres)) { hres = ppf->Load(sLnkFile, STGM_READ); if (SUCCEEDED(hres)) { // Resolve the link. hres = psl->Resolve(hwnd, SLR_ANY_MATCH); if (SUCCEEDED(hres)) { // Get the path to the link target. hres = psl->GetPath(szGotPath, MAX_PATH, (WIN32_FIND_DATA *)&wfd, SLGP_SHORTPATH); LnkPath.ReleaseBuffer(); if (!SUCCEEDED(hres)) { LnkDescription.ReleaseBuffer(); return hres; // application-defined function } // Get the description of the target: hres = psl->GetDescription(szDescription, MAX_PATH); LnkDescription.ReleaseBuffer(); if (!SUCCEEDED(hres)) return hres; } } // Release the pointer to the IPersistFile interface. ppf->Release(); } // Release the pointer to the IShellLink interface. psl->Release(); } // whether OS is <= NT4 or not... use this helper: if (ShortToLongPathName(LnkPath, sLong) > LnkPath.GetLength()) LnkPath = sLong; return hres; }
BOOL CShortcut::CreateShortCut(const CString &LnkTarget, const CString &LnkName, UINT SpecialFolder, const CString &LnkDescription, const CString &IconLocation, UINT IconIndex) { CFile cfFull; CString sExePath, sExe, sSpecialFolder; wchar_t *chTmp = sExePath.GetBuffer(MAX_PATH); GetModuleFileName(NULL, chTmp, MAX_PATH); sExePath.ReleaseBuffer(); // Find the Special Folder: if (!GetSpecialFolder(SpecialFolder, sSpecialFolder)) return FALSE; sSpecialFolder += LnkName + L"." + L"lnk"; if (LnkTarget == L"_this") { cfFull.SetFilePath(sExePath); sExe = cfFull.GetFileName(); sExe.Delete(sExe.Find(L".") + 1, 3); } else { sExePath = LnkTarget; } // Create the ShortCut: CoInitialize(NULL); BOOL bRet = FALSE; IShellLink* psl; if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &psl))) { IPersistFile* ppf; psl->SetPath(sExePath); psl->SetDescription(LnkDescription); if (!m_sCmdArg.IsEmpty()) psl->SetArguments(m_sCmdArg); if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf))) { /* Call IShellLink::SetIconLocation with the file containing the icon and the index of the icon */ if (!IconLocation.IsEmpty()) { HRESULT hr = psl->SetIconLocation(IconLocation, IconIndex); #ifdef _DEBUG if (FAILED(hr)) pws_os::Trace(L"IconLocation not changed!\n"); #endif } if (SUCCEEDED(ppf->Save(sSpecialFolder, TRUE))) { bRet = TRUE; } ppf->Release(); } psl->Release(); } pws_os::Trace(bRet ? L"Lnk Written!\n" : L"Lnk NOT Written! CreateShortCut(...) failed!\n"); return bRet; }
BOOL CWedApp::InitInstance() { CString str; char *ptr; //SetDialogBkColor(0x00ff0000, 0xffffff); WaitCursor = AfxGetApp()->LoadStandardCursor(IDC_WAIT); NormalCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); GetModuleFileName(AfxGetInstanceHandle(), approot, MAX_PATH); CTime ct = CTime::GetCurrentTime(); CString datestr = ct.Format("%A, %B %d, %Y - %I:%M %p"); C2N(); P2N("\r\nStarted WED application at %s\r\n", datestr); //P2N("AppRoot=%s\r\n", approot); //CString desktop; //GetSpecialFolder(CSIDL_DESKTOPDIRECTORY, desktop); //desktop += "wed"; //P2N("Desktop special: %s\r\n", desktop); // Create initial desktop xcpt folder //if(access(desktop, 0) == -1) // { // P2N("Making %s\r\n", desktop); // //message("Created desktop folder."); // _mkdir(desktop); // } ptr = strrchr(approot, '\\'); if(ptr) *(ptr+1) = '\0'; //dataroot = (CString)approot + "wed\\"; GetSpecialFolder(CSIDL_PERSONAL, dataroot); dataroot += "WedData\\"; P2N("Wed user data directory: %s\r\n", dataroot); if(access(dataroot, 0)) { if(mkdir(dataroot)) { //P2N("Cannot create data root dir\r\n"); } } ////////////////////////////////////////////////////////////////////// // Create data dirs str = dataroot; str += "data"; // Check if data dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create data dir\r\n"); } } str = dataroot; str += "macros"; // Check if data dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create macro dir\r\n"); } } str = dataroot; str += "holdings"; // Check if data dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create holders dir\r\n"); } } str = dataroot; str += "coco"; // Check if coco dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create coco dir\r\n"); } } str = dataroot; str += "backup"; // Check if state dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create state dir\r\n"); } } str = dataroot; str += "template"; // Check if state dir is in order if(access(str, 0)) { if(mkdir(str)) { //P2N("Cannot create template dir\r\n"); } } //P2N("Started Application: %s %s\r\n", // m_pszAppName, approot); getcwd(str.GetBuffer(MAX_PATH), MAX_PATH); str.ReleaseBuffer(); //P2N("Initial dir: %s\r\n", str); if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } // Initialize OLE 2.0 libraries if (!AfxOleInit()) { AfxMessageBox("Failed OLE library init, OLE functions will not be available"); } AfxEnableControlContainer(); #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("RobotMonkeySoftware")); LoadStdProfileSettings(6); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. pDocTemplate = new CMultiDocTemplate( IDR_WEDTYPE, RUNTIME_CLASS(CWedDoc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CWedView)); AddDocTemplate(pDocTemplate); // create main MDI Frame window pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; // Global m_pMainWnd = pMainFrame; // Get resources we need: // 1. Fonts CString fontname = GetProfileString(strConfig, strFontName, "Courier"); int size = GetProfileInt(strConfig, strFontSize, 10); int weight = GetProfileInt(strConfig, strFontWeight, 0); int italic = GetProfileInt(strConfig, strFontItalic, 0); if(!ff.CreateFont(size, 0, 0, 0, weight, italic, 0, 0, 0, 0, 0, 0, FIXED_PITCH, fontname)) { AfxMessageBox("Cannot set font"); } if(!ff.GetLogFont(&fflf)) { AfxMessageBox("Cannot get font parameters"); } // 2. Printer fonts if(!pp.CreateFont(80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FF_MODERN, "system")) { MessageBox(NULL, "Cannot set font", "Wed", 0); } if(!pp.GetLogFont(&pplf)) { MessageBox(NULL, "Cannot get font parameters", "Wed", 0); } // Get colors bgcol = GetProfileInt(strConfig, strColorBg, bgcol); fgcol = GetProfileInt(strConfig, strColorFg, fgcol); selcol = GetProfileInt(strConfig, strColorSel , selcol ); cselcol = GetProfileInt(strConfig, strColorCSel, cselcol); cadd = GetProfileInt(strConfig, strColorAdd , cadd ); cdel = GetProfileInt(strConfig, strColorDel , cdel ); cchg = GetProfileInt(strConfig, strColorChg , cchg ); comm = GetProfileInt(strConfig, strColorComm, comm ); srcc = GetProfileInt(strConfig, strColorSrc , srcc ); clng = GetProfileInt(strConfig, strColorLong, clng ); // Bimaps caret.LoadBitmap(IDB_BITMAP1); backwrap = GetProfileInt(strConfig, strBackWrap , 0); Tab2Space = GetProfileInt(strConfig, strTab2Space, 0); tabstop = GetProfileInt(strConfig, strTabStop, 4); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if(cmdInfo.m_strFileName != "") { comline = TRUE; OpenDocumentFile(cmdInfo.m_strFileName); } else { // DON'T display a new MDI child window during startup!!! cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; } // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // Key settings // Figure out last usage time ... int last = GetProfileInt(strConfig, "strLastUsage", 0); use = GetProfileInt(strConfig, "strUsage", 0); //P2N("Usage count %d \r\n", use); // First time ever, display initial file if(!use) { OpenDocumentFile("Welcome.txt"); comline = TRUE; if(currentedit) { } } use++; CTime tt = CTime::GetCurrentTime(); CTimeSpan t(tt.GetTime() - (time_t)last); //P2N("Time diff of last fire %d -- %d \r\n", // t.GetTotalSeconds(), (int)tt.GetTime()); YieldToWin() ; // Show sign banner only if more then 60 seconds passed //if(t.GetTotalSeconds() > 60) { spp.Create(IDD_DIALOG5, NULL); spp.Show(); } YieldToWin() ; //if(GetKeyState(VK_SHIFT)) // { // AfxMessageBox("SHIFT HELD on startup\r\n"); // return(TRUE); // } // The main window has been initialized ... // Show and update it. m_nCmdShow = GetProfileInt(strConfig, "WindowState", 1); pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); int num = GetProfileInt(strSection, strIntItem, 0); // De-serialize hash map CMap < int, int&, CString, CString& > HashMap; CFile cf; CString fname; fname.Format("%s%s", dataroot, "macros\\hashes.000"); if( cf.Open( fname, CFile::modeRead)) { CArchive ar( &cf, CArchive::load); HashMap.Serialize(ar); } else { //P2N("Cannot open hash map file: %s\r\n", fname); } POSITION rpos; rpos = HashMap.GetStartPosition(); while(rpos) { int key; CString val; HashMap.GetNextAssoc(rpos, key, val); //P2N("In Hashlist: %x %s\r\n", key, val); } if(!comline) { // Reopen old documents: CString buf2, file; for(int count1 = 1; count1 <= num; count1++) { CWedDoc *doc = NULL; buf2.Format("%d", count1); file = GetProfileString(strSection, strStringItem + buf2); //P2N("Reloading file: '%s' at %s\r\n", file, buf2); // Empty file, no action if(file == "") continue; doc = (CWedDoc*)OpenDocumentFile(file); if(YieldToWinEx()) break; //P2N("After Reloading file: %s at %s\r\n", file, buf2); if(doc) { ASSERT_VALID(doc); // Document had an error if(doc->ssel.m_err) break; int lrow, lcol; lrow = GetProfileInt(strSection, strStringItem + buf2 + "row", 0); lcol = GetProfileInt(strSection, strStringItem + buf2 + "col", 0); // Update cursor positions ... POSITION pos = doc->GetFirstViewPosition(); for(;;) { if(!pos) break; CWedView *cv = (CWedView*)doc->GetNextView(pos); if(cv) { ASSERT_VALID(cv); cv->row = lrow; cv->col = lcol; cv->SyncCaret(); YieldToWin() ; } } // This happens after load, set it again doc->UpdateAllViews(NULL); } } // Try figure out last current directory int idx; if( (idx = file.ReverseFind('\\')) != -1) { file = file.Left(idx + 1); } P2N("CWedApp::InitInstance Chdir: '%s'\r\n", file); _chdir(file); targdir = srcdir = file; } message ("Loading macros ..."); LoadMacros(); message ("Loading holdings ..."); LoadHoldings(); message(""); return TRUE; }
CString ABPLTools::GetWorkingFolder() { CString appLocal = GetSpecialFolder() + TEXT("\\ABP Launcher\\"); CreateDirectory(appLocal); return appLocal; }
void CSVNStatusCache::Create() { ATLASSERT(m_pInstance == NULL); if (m_pInstance != NULL) return; m_pInstance = new CSVNStatusCache; m_pInstance->watcher.SetFolderCrawler(&m_pInstance->m_folderCrawler); #define LOADVALUEFROMFILE(x) if (fread(&x, sizeof(x), 1, pFile)!=1) goto exit; #define LOADVALUEFROMFILE2(x) if (fread(&x, sizeof(x), 1, pFile)!=1) goto error; unsigned int value = (unsigned int)-1; FILE * pFile = NULL; // find the location of the cache CString path = GetSpecialFolder(FOLDERID_LocalAppData); CString path2; if (!path.IsEmpty()) { path += L"\\TSVNCache"; if (!PathIsDirectory(path)) { DeleteFile(path); if (CreateDirectory(path, NULL)==0) goto error; } path += STATUSCACHEFILENAME; // in case the cache file is corrupt, we could crash while // reading it! To prevent crashing every time once that happens, // we make a copy of the cache file and use that copy to read from. // if that copy is corrupt, the original file won't exist anymore // and the second time we start up and try to read the file, // it's not there anymore and we start from scratch without a crash. path2 = path; path2 += L"2"; DeleteFile(path2); CopyFile(path, path2, FALSE); DeleteFile(path); pFile = _tfsopen(path2, L"rb", _SH_DENYNO); if (pFile) { try { LOADVALUEFROMFILE(value); if (value != CACHEDISKVERSION) { goto error; } int mapsize = 0; LOADVALUEFROMFILE(mapsize); for (int i=0; i<mapsize; ++i) { LOADVALUEFROMFILE2(value); if (value > MAX_PATH) goto error; if (value) { CString sKey; if (fread(sKey.GetBuffer(value+1), sizeof(TCHAR), value, pFile)!=value) { sKey.ReleaseBuffer(0); goto error; } sKey.ReleaseBuffer(value); std::unique_ptr<CCachedDirectory> cacheddir (new CCachedDirectory()); if (!cacheddir.get() || !cacheddir->LoadFromDisk(pFile)) { cacheddir.reset(); goto error; } CTSVNPath KeyPath = CTSVNPath(sKey); if (m_pInstance->IsPathAllowed(KeyPath)) { // only add the path to the watch list if it is versioned if ((cacheddir->GetCurrentFullStatus() != svn_wc_status_unversioned)&&(cacheddir->GetCurrentFullStatus() != svn_wc_status_none)) m_pInstance->watcher.AddPath(KeyPath, false); m_pInstance->m_directoryCache[KeyPath] = cacheddir.release(); // do *not* add the paths for crawling! // because crawled paths will trigger a shell // notification, which makes the desktop flash constantly // until the whole first time crawling is over // m_pInstance->AddFolderForCrawling(KeyPath); } } } } catch (CAtlException) { goto error; } } } exit: if (pFile) fclose(pFile); if (!path2.IsEmpty()) DeleteFile(path2); m_pInstance->watcher.ClearInfoMap(); CTraceToOutputDebugString::Instance()(__FUNCTION__ ": cache loaded from disk successfully!\n"); return; error: if (pFile) fclose(pFile); if (!path2.IsEmpty()) DeleteFile(path2); m_pInstance->watcher.ClearInfoMap(); Destroy(); m_pInstance = new CSVNStatusCache; CTraceToOutputDebugString::Instance()(__FUNCTION__ ": cache not loaded from disk\n"); }