void GetDefaultAspellPath (TCHAR *&Path) { TCHAR pszPath[MAX_PATH]; pszPath[0] = '\0'; HKEY hKey = NULL; DWORD size = MAX_PATH; if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T ("SOFTWARE\\Aspell"), 0, KEY_READ, &hKey)) { if (ERROR_SUCCESS == ::RegQueryValueEx(hKey, _T ("Path"), NULL ,NULL, (LPBYTE)pszPath, &size)) wcscat(pszPath, _T ("\\aspell-15.dll")); ::RegCloseKey(hKey); } else { TCHAR Pf[MAX_PATH]; SHGetSpecialFolderPath( 0, Pf, CSIDL_PROGRAM_FILES, FALSE ); PathAppend(pszPath, Pf); PathAppend(pszPath, _T("\\Aspell\\bin\\aspell-15.dll")); } SetString (Path, pszPath); }
void CEyepatch::LoadCreateModeClassifiers() { WCHAR rootpath[MAX_PATH]; WCHAR searchpath[MAX_PATH]; WCHAR fullpath[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, rootpath); PathAppend(rootpath, APP_CLASS); wcscpy(searchpath,rootpath); PathAppend(searchpath, L"*.*"); HANDLE hFind; WIN32_FIND_DATA win32fd; if ((hFind = FindFirstFile(searchpath, &win32fd)) == INVALID_HANDLE_VALUE) { return; } do { if (win32fd.cFileName[0] != '.' && (win32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(win32fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) { wcscpy(fullpath, rootpath); PathAppend(fullpath, win32fd.cFileName); m_videoMarkup.LoadClassifier(fullpath); } } while(FindNextFile(hFind, &win32fd) != 0); FindClose(hFind); }
bool AddDxccDllPath(CStringA& ErrorMsg) { ErrorMsg= "No Errors"; #define DXCC_PATH TEXT("..\\..\\..\\..\\x86\\") #define DXCC_FILE TEXT("DXCC.DLL") HMODULE hMLL = GetModuleHandle(TEXT(THISFILENAME)); TCHAR mllPath[MAX_PATH]; DWORD mllPathLen = GetModuleFileName(hMLL, mllPath, MAX_PATH); if (!(mllPathLen != 0 && mllPathLen < MAX_PATH)) { ErrorMsg= "Could not fetch this module's filename and length."; return false; } TCHAR fullPath[MAX_PATH]; TCHAR* fileName; DWORD fullPathLen = GetFullPathName(mllPath, MAX_PATH, fullPath, &fileName); if (!(fullPathLen != 0 && fullPathLen < MAX_PATH && fileName)) { ErrorMsg= "Could not fetch the full path of this module."; return false; } fileName[0] = 0; // lop off file name from path //no need to add the current path at this time //we dont want local overrides at this time //PrependPathToEnv(fullPath); PathAppend(fullPath, DXCC_PATH); PrependPathToEnv(fullPath); HMODULE hDXCC = LoadLibrary(DXCC_FILE); if(hDXCC == NULL) { ErrorMsg="DXCC.DLL could not be found"; return false; } PathAppend(fullPath, DXCC_FILE); TCHAR dxccPath[MAX_PATH]; DWORD dxccPathLen = GetModuleFileName(hDXCC, dxccPath, MAX_PATH); if( 0 != lstrcmpi( fullPath , dxccPath ) ) { ErrorMsg.Format( "Incompatable DXCC.DLL was loaded: %S\nDesired DXCC.DLL is in path: %S", dxccPath, fullPath); return false; } ErrorMsg= "No Errors"; return true; }
LPCTSTR GetKeyBoard(UINT Index, TCHAR * szKBPath){ TCHAR szINI[MAX_PATH]; TCHAR szKBNames[500]; TCHAR szKBFile[MAX_PATH]; TCHAR szAllUser[MAX_PATH]; TCHAR szKBP[] = TEXT("KeyBoardPaths"); lstrcpy(szINI,szDir); PathAppend(szINI, TEXT("KeyMagic.ini")); GetPrivateProfileString(szKBP, NULL, NULL, (LPTSTR)szKBNames, 500, szINI); for (int i=0,Length = lstrlen(&szKBNames[i]),j=0; j <= Index; i+=Length+1, j++, Length = lstrlen(&szKBNames[i])){ GetPrivateProfileString(szKBP, (LPCTSTR)&szKBNames[i], NULL, (LPTSTR)szKBFile, MAX_PATH, szINI); } if (szKBFile[1] == ':'){ lstrcpy(szKBPath, szKBFile); return szKBPath; } lstrcpy(szKBPath, szDir); PathAppend(szKBPath, szKBFile); return szKBPath; }
/** * @brief Create complete log file name. * @param pszCompleteLogFileName - output complete file name. * @param pszLogFileName - base log file name. * @param pszDefFileExtension - default extension. * @return true if log file name was created and false otherwise. */ BOOL GetCompleteLogFileName(PTSTR pszCompleteLogFileName, PCTSTR pszLogFileName, PCTSTR pszDefFileExtension) { if (pszLogFileName && *pszLogFileName && PathIsRoot(pszLogFileName)) { _tcscpy_s(pszCompleteLogFileName, MAX_PATH, pszLogFileName); return TRUE; } TCHAR szAppDataPath[MAX_PATH]; if (! SHGetSpecialFolderPath(NULL, szAppDataPath, CSIDL_APPDATA, TRUE)) return FALSE; TCHAR szAppName[MAX_PATH]; if (! GetCanonicalAppName(szAppName, countof(szAppName), TRUE)) return FALSE; TCHAR szAppFileName[MAX_PATH]; if (! GetModuleFileName(NULL, szAppFileName, countof(szAppFileName))) return FALSE; PTSTR pszFileName = PathFindFileName(szAppFileName); PathRemoveExtension(pszFileName); PTSTR pszAppName = *szAppName ? szAppName : pszFileName; PathCombine(pszCompleteLogFileName, szAppDataPath, pszAppName); if (pszLogFileName == NULL || *pszLogFileName == _T('\0')) { if (pszDefFileExtension == NULL || *pszDefFileExtension != _T('.')) return FALSE; PathAppend(pszCompleteLogFileName, pszFileName); PathAddExtension(pszCompleteLogFileName, pszDefFileExtension); } else PathAppend(pszCompleteLogFileName, pszLogFileName); return TRUE; }
static std::string settings_path(bool *firsttime) { TCHAR szPath[MAX_PATH]; if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath))) { FILE *f; PathAppend(szPath,TEXT("vrok")); CreateDirectory(szPath,NULL); PathAppend(szPath,TEXT("vrok.conf")); f=_wfopen(szPath,TEXT("r")); DBG(szPath); if (!f) { *firsttime = true; } else { *firsttime = false; fclose(f); } char upath[1024]; WideCharToMultiByte(CP_UTF8,0,szPath,-1,upath,1024,0,NULL); return std::string(upath); } else { DBG("Can't get settings path, exiting"); exit(-1); } }
BOOL spool_instance_isAlive(P_SPOOL spool, int instance) { TCHAR path[MAX_PATH]; TCHAR instance_str[32]; snprintf(instance_str, sizeof(instance_str), "%d", instance); snprintf(path, sizeof(path), "%s", spool->path); if (PathAppend(path, SPOOL_DIR_INSTANCE) == FALSE) { fprintf(stderr, "PathAppend error\n"); return FALSE; } if (PathAppend(path, instance_str) == FALSE) { fprintf(stderr, "PathAppend error\n"); return FALSE; } if (! PathFileExists(path)) { snprintf(instance_str, sizeof(instance_str), "%d", instance); snprintf(path, sizeof(path), "%s", spool->path); if (PathAppend(path, SPOOL_DIR_TOSTART) == FALSE) { fprintf(stderr, "PathAppend error\n"); return FALSE; } if (PathAppend(path, instance_str) == FALSE) { fprintf(stderr, "PathAppend error\n"); return FALSE; } return PathFileExists(path); } return TRUE; }
int spool_instance_create(P_SPOOL spool, const LPSTR appId, const LPSTR args) { int instance; TCHAR path[MAX_PATH]; TCHAR instance_str[32]; FILE *f = NULL; instance = spool_build_unique_id(spool); snprintf(instance_str, sizeof(instance_str), "%d", instance); snprintf(path, sizeof(path), "%s", spool->path); if (PathAppend(path, SPOOL_DIR_TOSTART) == FALSE) { fprintf(stderr, "PathAppend error\n"); return -1; } if (PathAppend(path, instance_str) == FALSE) { fprintf(stderr, "PathAppend error\n"); return -1; } f = fopen(path, "w"); if (! f) return -1; fprintf(f, "id = %s", appId); if (args != NULL && strlen(args) > 0) { fprintf(f, "\narg = %s", args); } fclose(f); return instance; }
/* ** Attempts to load Rainmeter.dll. If it fails, retries after loading our own copies of the CRT ** DLLs in the Runtime directory. */ HINSTANCE LoadRainmeterLibrary() { HINSTANCE rmDll = LoadLibrary(L"Rainmeter.dll"); if (!rmDll) { WCHAR path[MAX_PATH]; if (GetModuleFileName(nullptr, path, MAX_PATH) > 0) { PathRemoveFileSpec(path); PathAppend(path, L"Runtime"); SetDllDirectory(path); PathAppend(path, L"msvcp120.dll"); // Loading msvcpNNN.dll will load msvcrNNN.dll as well. HINSTANCE msvcrDll = LoadLibrary(path); SetDllDirectory(L""); if (msvcrDll) { rmDll = LoadLibrary(L"Rainmeter.dll"); FreeLibrary(msvcrDll); } } } return rmDll; }
HANDLE OpenLogFile() { SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, g_szLogFileName); const TCHAR* szCompanyName = Zephyros::GetCompanyName(); if (szCompanyName != NULL && szCompanyName[0] != TCHAR('\0')) { PathAddBackslash(g_szLogFileName); PathAppend(g_szLogFileName, szCompanyName); CreateDirectory(g_szLogFileName, NULL); } PathAddBackslash(g_szLogFileName); PathAppend(g_szLogFileName, Zephyros::GetAppName()); CreateDirectory(g_szLogFileName, NULL); PathAppend(g_szLogFileName, TEXT("\\debug.log")); HANDLE hndLogFile = CreateFile(g_szLogFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hndLogFile == INVALID_HANDLE_VALUE) { //AppShowErrorMessage(); hndLogFile = CreateFile(g_szLogFileName, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); } // write marker bytes to mark the file as UTF-8 encoded BYTE marker[] = { 0xef, 0xbb, 0xbf }; DWORD dwBytesWritten = 0; WriteFile(hndLogFile, marker, 3, &dwBytesWritten, NULL); return hndLogFile; }
//----------------------------------------------------------------------------- // ストレスファイルの削除 //----------------------------------------------------------------------------- void RemoveAll(LPCTSTR path) { WIN32_FIND_DATA data; TCHAR wc[MAX_PATH]; PathAppend(lstrcpy(wc, path), _T("*.*")); HANDLE hFind = FindFirstFile(wc, &data); if (hFind == INVALID_HANDLE_VALUE) { return; } do { if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { TCHAR fname[MAX_PATH]; PathAppend(lstrcpy(fname, path), data.cFileName); _tprintf(_T("削除 '%s' ... "), fname); if (DeleteFile(fname)) { _tprintf(_T("done\n")); } else { _tprintf(_T("error %d\n"), GetLastError()); } } } while (FindNextFile(hFind, &data)); FindClose(hFind); }
BOOL CSpecialApp::ScanXunleiSearch(int iType) { KSearchSoftwareStruct sss; std::vector<std::wstring>::iterator it; WCHAR szPath[MAX_PATH] = {0}; sss.pszMainFileName = TEXT( "Program\\thunder.exe" ); sss.hRegRootKey = HKEY_LOCAL_MACHINE; sss.pszRegSubKey = TEXT( "SOFTWARE\\Thunder Network\\ThunderOem\\thunder_backwnd" ); sss.pszPathValue = TEXT( "dir" ); sss.bFolder = TRUE; BOOL bRet = FALSE; std::wstring str; std::wstring strPath; std::wstring strTemp; bRet = SearchSoftwarePath( &sss, strPath); wcscpy_s(szPath, MAX_PATH - 1, strPath.c_str()); PathRemoveFileSpec(szPath); PathRemoveFileSpec(szPath); PathAppend(szPath, L"Profiles\\GougouSearch\\history.history"); strPath = szPath; if (GetFileAttributes(strPath.c_str()) == INVALID_FILE_ATTRIBUTES) { WCHAR* pEnv = NULL; WCHAR szPath[MAX_PATH] = {0}; pEnv = _wgetenv(_T("public")); if (pEnv != NULL) { wcscpy(szPath, pEnv); PathAppend(szPath, L"Documents\\Thunder Network\\Thunder\\Profiles\\GougouSearch\\history.history"); strPath = szPath; } else { return TRUE; } } g_fnScanFile(g_pMain, BEGINPROC(XUNLEI7_DOWNLOADER), 0, 0, 0); for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ ) { str = *it; transform(str.begin(), str.end(), str.begin(), towlower); if (str == L"thunder.exe") { str = L"正在运行,跳过"; goto clean0; } } str = L""; if (m_bScan) { ModifyTxtData(iType, strPath.c_str()); // m_appHistory.CommfunFile(KUWOMUSIC_PLAYER, strPath.c_str(), vec_file); } clean0: g_fnScanFile(g_pMain, ENDPROC(XUNLEI7_DOWNLOADER), str.c_str(), 0, 0); return TRUE; }
CString &CompletePathWithModulePath(CString &strPath, LPCTSTR lpszFilename) { TCHAR szPath[MAX_PATH] = {0}; ::GetModuleFileName( (HMODULE)&__ImageBase, szPath, MAX_PATH); PathAppend(szPath, _T("..\\")); PathAppend(szPath, lpszFilename); strPath = szPath; return strPath; }
BOOL CKSogoClean::ScanSogoAdvForm() { if (!_CheckSogouExist()) { g_vsNoinstallapp.Add(SOGO_ADVFORM); return TRUE; } BOOL bRet = FALSE; WCHAR szSogoAppPath[MAX_PATH] = {0}; std::wstring strTemp; SHGetSpecialFolderPath(NULL, szSogoAppPath, CSIDL_APPDATA, FALSE); PathAppend(szSogoAppPath, L"SogouExplorer"); strTemp = szSogoAppPath; PathAppend(szSogoAppPath, L"FormData.dat"); g_fnScanFile(g_pMain,BEGINPROC(SOGO_ADVFORM),0,0,0); std::wstring str; std::vector<std::wstring>::iterator it; for (it = g_listProcessName.begin(); it != g_listProcessName.end(); it++ ) { str = *it; transform(str.begin(), str.end(), str.begin(), towlower); if (str == L"sogouexplorer.exe") { str = L"正在运行,跳过"; goto clean0; } } str = L""; if (m_bScan) { ScanDbTable(szSogoAppPath, L"IndexPrecise", SOGO_ADVFORM); ScanDbTable(szSogoAppPath, L"PreciseData", SOGO_ADVFORM); std::vector<std::wstring> vec_userInfo; std::vector<std::wstring>::iterator it; if (GetUserInfo(vec_userInfo)) { for (it = vec_userInfo.begin(); it != vec_userInfo.end(); it++) { std::wstring strUserPath; strUserPath = strTemp; strUserPath += L"\\"; strUserPath += *it; strUserPath += L"\\FormData.dat"; ScanDbTable(strUserPath, L"IndexPrecise", SOGO_ADVFORM); ScanDbTable(strUserPath, L"PreciseData", SOGO_ADVFORM); } } } clean0: g_fnScanFile(g_pMain,ENDPROC(SOGO_ADVFORM),str.c_str(),0,0); return bRet; }
std::string GetPiUserDir(const std::string &subdir) { // i think this test only works with glibc... #if _GNU_SOURCE const char *homedir = getenv("HOME"); std::string path = join_path(homedir, ".pioneer", 0); DIR *dir = opendir(path.c_str()); if (!dir) { if (mkdir(path.c_str(), 0770) == -1) { Gui::Screen::ShowBadError(stringf(128, "Error: Could not create or open '%s'.", path.c_str()).c_str()); } } closedir(dir); if (subdir != "") { path = join_path(homedir, ".pioneer", subdir.c_str(), 0); dir = opendir(path.c_str()); if (!dir) { if (mkdir(path.c_str(), 0770) == -1) { Gui::Screen::ShowBadError(stringf(128, "Error: Could not create or open '%s'.", path.c_str()).c_str()); } } closedir(dir); } return path+"/"; #elif _WIN32 try { TCHAR path[MAX_PATH]; if(S_OK != SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, SHGFP_TYPE_CURRENT, path)) throw std::runtime_error("SHGetFolderPath"); TCHAR temp[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, "Pioneer", strlen("Pioneer")+1, temp, MAX_PATH); if(!PathAppend(path, temp)) throw std::runtime_error("PathAppend"); if (subdir != "") { MultiByteToWideChar(CP_ACP, 0, subdir.c_str(), subdir.size()+1, temp, MAX_PATH); if(!PathAppend(path, temp)) throw std::runtime_error("PathAppend"); } if(!PathFileExists(path) && ERROR_SUCCESS != SHCreateDirectoryEx(0, path, 0)) throw std::runtime_error("SHCreateDirectoryEx"); char temp2[MAX_PATH]; WideCharToMultiByte(CP_ACP, 0, path, wcslen(path)+1, temp2, MAX_PATH, 0, 0); return std::string(temp2)+"/"; } catch(const std::exception&) { Gui::Screen::ShowBadError("Can't get path to save directory"); return ""; } #else # error Unsupported system #endif }
static void GetIniPath(void) { TCHAR me[MAX_PATH]; HRESULT hResult = SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, me); PathAppend(me, _T("TTSwTask")); SHCreateDirectoryEx(NULL, me, NULL); PathAppend(me, _T("TTSwTask.ini")); g_IniPath = CopyString(me); }
//目录拷贝 int Lua_Test::Lua_copyPath(LuaPlus::LuaState* state) { LuaStack args(state); if(!(args[2].IsString())) { throw std::exception("TestUtil::copyPath[2] param parameter error"); } if(!(args[3].IsString())) { throw std::exception("TestUtil::copyPath[3] param parameter error"); } if(!(args[4].IsBoolean())) { throw std::exception("TestUtil::copyPath[4] param parameter error"); } const char* szPath1 = args[2].GetString(); const char* szPath2 = args[3].GetString(); bool bRecusive = args[4].GetBoolean(); _log("copy path%s \"%s\" -> \"%s\"", bRecusive ? "[R]" : "", szPath1, szPath2); //清空Path2 char szTemp[MAX_PATH]; strncpy(szTemp, szPath2, MAX_PATH); PathAppend(szTemp, "*.*"); SHFILEOPSTRUCT shf; memset(&shf,0,sizeof(SHFILEOPSTRUCT)); shf.hwnd = NULL; shf.pFrom = szTemp; shf.wFunc = FO_DELETE; shf.fFlags = FOF_NOCONFIRMMKDIR|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT; SHFileOperation(&shf); CreateDirectory(szPath2, 0); //copy path1 -> path2 strncpy(szTemp, szPath1, MAX_PATH); PathAppend(szTemp, "*.*"); memset(&shf,0,sizeof(SHFILEOPSTRUCT)); shf.hwnd = NULL; shf.pFrom = szTemp; shf.pTo = szPath2; shf.wFunc = FO_COPY; shf.fFlags = bRecusive ? FOF_NOCONFIRMMKDIR|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT : FOF_NOCONFIRMMKDIR|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT|FOF_NORECURSION|FOF_FILESONLY; SHFileOperation(&shf); return 0; }
void getDbPath(char* path) { char* envValue; if ((envValue = getenv(ENV_DB)) == NULL) { /* If the 'BITMETER_DB' environment variable hasn't been set then we expect the database to exist in the 'All Users\Application Data\BitMeterOS folder. */ SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path); PathAppend(path, TEXT(OUT_DIR)); PathAppend(path, TEXT(DB_NAME)); } else { // The 'BITMETER_DB' environment variable is set, so use that location instead. strcpy(path, envValue); } }
// 初始化延时时间 void InitDelayTime() { TCHAR szFilePath[MAX_PATH] = { 0 }; GetModuleFileName(NULL, szFilePath, MAX_PATH); PathAppend(szFilePath, _T("..\\..\\")); PathAppend(szFilePath, _T("data2\\mc.dat")); IXMLRW xml; xml.init(szFilePath); xml.ReadInt(_T("MC"), _T("QuickPhoto"), _T("delay_for_each_keyword"), g_iDelayForKeyWord, -1); xml.ReadInt(_T("MC"), _T("QuickPhoto"), _T("delay_for_each_site"), g_iDalayForSite, -1); xml.ReadInt(_T("MC"), _T("QuickPhoto"), _T("count"), g_iThreadCount, -1); g_pageLog.Trace(LOGL_TOP, LOGT_PROMPT, __TFILE__, __LINE__, _T("初始化数据:%d,%d,%d"), g_iDalayForSite, g_iDelayForKeyWord, g_iThreadCount); }
std::string ConfigurationPath(const std::string& name) { TCHAR path[MAX_PATH]; if (SUCCEEDED(SHGetFolderPath( nullptr, CSIDL_APPDATA, nullptr, 0, path))) { PathAppend(path, TEXT("\\SynchronousAudioRouter\\")); CreateDirectory(path, nullptr); PathAppend(path, UTF8ToWide(name).c_str()); } return TCHARToUTF8(path); }
// IMPLEMENTATION FILE CSkinEnumerator::CSkinEnumerator(HINSTANCE hInstance, const wchar_t* deskletPath) { char path[MAX_PATH+1] = {0}; _bstr_t _path_t(deskletPath); strcpy(path, _path_t); PathAppend(path,"configs\\"); // search in the configs directory for skins/configs. _bstr_t s = path; s += "*.ini"; // only make INI files show up in our search WIN32_FIND_DATA data = {0}; HANDLE h = FindFirstFile(s, &data); if(h != INVALID_HANDLE_VALUE) { do { if(strcmp(data.cFileName,".") != 0 && strcmp(data.cFileName,"..") != 0) { char file[MAX_PATH+1] = {0}; strcpy(file, path); PathAppend(file, data.cFileName); CSkinValue value; value.filename = file; ::PathRemoveExtension(data.cFileName); char buf[1024]; ::GetPrivateProfileString("General", "name", data.cFileName, buf, sizeof(buf), file); if (*buf == 0) { // name property was left blank strncpy(buf, data.cFileName, sizeof(buf)); } value.name = buf; ::GetPrivateProfileString("General", "author", "", buf, sizeof(buf), file); value.author = buf; ::GetPrivateProfileString("General", "dversion", "", buf, sizeof(buf), file); value.version = buf; ::GetPrivateProfileString("General", "description", "", buf, sizeof(buf), file); value.description = buf; m_Skins[_bstr_t(data.cFileName)] = value; } } while (FindNextFile(h,&data)); FindClose(h); } }
void getLogPath(char* path) { char* configValue; if ((isDbOpen() == FALSE) || (configValue = getConfigText(CONFIG_LOG_PATH, TRUE)) == NULL) { /* If an alternative path has not been specified in the db config table, or if the database isn't open yet, then we write the log out to the 'All Users\Application Data\BitMeterOS' folder. */ SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, 0, path); PathAppend(path, TEXT(OUT_DIR)); PathAppend(path, TEXT(LOG_NAME)); } else { // A value was supplied in the config table, so use that location instead. strcpy(path, configValue); } }
CString FileMgr::GetAppPathById(const CString& strId, const CString& strSub) { CString strPath = GetAppPath(); TCHAR szPath[MAX_PATH] = { 0 }; StrCpy(szPath, strPath); PathAppend(szPath, strId); PathAppend(szPath, strSub); strPath = szPath; if (!PathFileExists(szPath)) { SHCreateDirectoryEx(NULL, szPath, NULL); } return strPath; }
//压缩日志 void CLogTrace::CompressLogzip(const CString &strLogFileName) { time_t tim; time(&tim); struct tm *t; t = localtime(&tim); //先压缩 CString strName; CString strFilename; CString strTmpFile; strFilename = strLogFileName.Left(strLogFileName.GetLength() - 4); strName.Format(_T("%s_%04d%02d%02d%02d%02d%02d.zip"), strFilename.GetString(), 1900 + t->tm_year, 1 + t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); DWORD dwCode = ZipUtils::CompressFileToZip(strLogFileName, strName); /*CopyFile(m_szFullLogFileName, strDate.GetBuffer(), FALSE);*/ //移动到备份文件夹 int iPos = strName.ReverseFind(_T('\\')); strFilename = strName.Right(strName.GetLength() - iPos); TCHAR szPath[MAX_PATH] = { 0 }; if (GetModuleFileName(NULL, szPath, MAX_PATH)) { PathAppend(szPath, _T("..\\..\\..\\bak\\masterz")); SHCreateDirectoryEx(NULL, szPath, NULL); strTmpFile.Format(_T("%s%s"), szPath, strFilename.GetString()); MoveFile(strName, strTmpFile); } }
void AddDxccDllPath(void) { HMODULE dll = GetModuleHandle("DXExtensionsMax.gup"); TCHAR dllPath[MAX_PATH]; DWORD dllPathLen = GetModuleFileName(dll, dllPath, MAX_PATH); if (dllPathLen != 0 && dllPathLen < MAX_PATH) { TCHAR fullPath[MAX_PATH]; TCHAR* fileName; DWORD fullPathLen = GetFullPathName(dllPath, MAX_PATH, fullPath, &fileName); if (fullPathLen != 0 && fullPathLen < MAX_PATH && fileName) { fileName[0] = 0; // lop off file name from path AppendPathToEnv(fullPath); PathAppend(fullPath, "..\\..\\..\\x86\\"); AppendPathToEnv(fullPath); } } }
static void getUsersFile(char * buffer, int bufSize) { HKEY key = NULL; if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\U.S. Robotics\\Pilot Desktop\\Core", 0, KEY_READ, &key)) { DWORD dwSize = bufSize; DWORD type; RegQueryValueEx(key, "Path", 0, &type, buffer, &dwSize); PathAppend(buffer, "users.dat"); RegCloseKey(key); } }
/*! インスタンス ハンドルを保存して、メイン ウィンドウを作成します。 この関数で、グローバル変数でインスタンス ハンドルを保存し、 メイン プログラム ウィンドウを作成および表示します。 @param[in] hInstance インスタンスハンドル @param[in] nCmdShow 起動時の表示状態 */ BOOL InitInstance( HINSTANCE hInstance, int nCmdShow ) { HWND hWnd; INT xxx, yyy; RECT rect; BOOL bHotRslt; ghInst = hInstance; // グローバル変数にインスタンス処理を格納します。 // 設定ファイル位置確認 GetModuleFileName( hInstance, gatIniPath, MAX_PATH ); PathRemoveFileSpec( gatIniPath ); PathAppend( gatIniPath, INI_FILE ); // ここらで初期設定確保 gbClipSteal = InitParamValue( INIT_LOAD, VL_COLLECT_AON, 0 ); // コピペ保存・デフォは起動時OFF gGetMsgOn = InitParamValue( INIT_LOAD, VL_USE_BALLOON, 1 ); gbUniRadixHex = InitParamValue( INIT_LOAD, VL_UNIRADIX_HEX, 0 ); // 初期設定は Ctrl+Shift+C gbHotMod = InitParamValue( INIT_LOAD, VL_COLHOT_MODY, (MOD_CONTROL | MOD_SHIFT) ); gbHotVkey = InitParamValue( INIT_LOAD, VL_COLHOT_VKEY, VK_C ); hWnd = GetDesktopWindow( ); GetWindowRect( hWnd, &rect ); xxx = ( rect.right - WCL_WIDTH ) / 2; yyy = ( rect.bottom - WCL_HEIGHT ) / 2; hWnd = CreateWindowEx( WS_EX_TOOLWINDOW | WS_EX_APPWINDOW, gatWindowClass, gatTitle, WS_CAPTION | WS_POPUPWINDOW, xxx, yyy, WCL_WIDTH, WCL_HEIGHT, NULL, NULL, hInstance, NULL); if( !hWnd ){ return FALSE; } // タスクトレイがあぼ〜んしたときの再起動メッセージ番号を確保 grdTaskbarResetID = RegisterWindowMessage( TEXT("TaskbarCreated") ); // クリップボードチェーンに自分を登録 ghNextViewer = SetClipboardViewer( hWnd ); FileListViewInit( hWnd ); // リスト初期化 FileListViewGet( hWnd, 0, gatClipFile ); // 取り込みファイルを確保しておく FileTypeCheck( gatClipFile ); // ASTかそうでないかを確認 if( gGetMsgOn ){ Button_SetCheck( GetDlgItem(hWnd,IDB_CLIP_USE_BALLOON) , BST_CHECKED ); } if( gbUniRadixHex ){ Button_SetCheck( GetDlgItem(hWnd,IDB_CLIP_UNIRADIX_HEX) , BST_CHECKED ); } if( gbClipSteal ){ Button_SetCheck( GetDlgItem(hWnd,IDB_CLIP_STEAL_ACT_ON) , BST_CHECKED ); } TasktrayIconAdd( hWnd ); // とりあえず、Ctrl+Shift+C bHotRslt = RegisterHotKey( hWnd, IDHK_CLIPSTEAL_FILECHANGE, gbHotMod, gbHotVkey ); ShowWindow( hWnd, SW_HIDE ); // SW_HIDE return TRUE; }
bool FindInDir(const char* Dir, char *Filename) { // First test if there's a Filename with exactly same name // and if yes, return it and do not search in the Dir char TempFilePath[_MAX_PATH]; strcpy(TempFilePath, Dir); PathAppend( TempFilePath, Filename ); if (!access( TempFilePath, R_OK )) { return true; } if (!core->CaseSensitive) { return false; } DirectoryIterator dir(Dir); if (!dir) { return false; } // Exact match not found, so try to search for Filename // with different case do { const char *name = dir.GetName(); if (stricmp( name, Filename ) == 0) { strcpy( Filename, name ); return true; } } while (++dir); return false; }
bool open_db(sqlite3 **db, const char *db_path) { int len = ::MultiByteToWideChar(CP_ACP, 0, db_path, -1, NULL, 0); if (len == 0) return false; wchar_t *wdb_path = (wchar_t *)malloc(sizeof(wchar_t)*len); ::MultiByteToWideChar(CP_ACP, 0, db_path, -1, wdb_path, len); char *errmsg=0;//记录返回的错误信息。 wchar_t wpath[MAX_PATH]; GetModuleFileName(NULL,wpath,MAX_PATH); PathAppend(wpath, wdb_path); free(wdb_path); len = ::WideCharToMultiByte(CP_UTF8, 0, wpath, -1, NULL, 0, NULL, NULL); if (len == 0) return false; char *upath = (char *)malloc(len); ::WideCharToMultiByte(CP_UTF8, 0, wpath, -1, upath, len, NULL, NULL); int rc=sqlite3_open(upath,db);//打开数据库 free(upath); CHECK_RC(rc,errmsg,*db); return true; }
void __cdecl DebugMsg(const char* pszFormat, ...) { FILE *stream; va_list arglist; char buf[1024]; sprintf(buf, "[%s](%lu): ", SERVICENAME, GetCurrentThreadId()); va_start(arglist, pszFormat); vsprintf(&buf[strlen(buf)], pszFormat, arglist); va_end(arglist); strcat(buf, "\n"); if ( fileName == NULL ) { SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS | CSIDL_FLAG_CREATE, NULL, 0, fileBuf); PathAppend(fileBuf, "clientApi.log"); fileName = fileBuf; } stream = fopen(fileName, "a+"); if ( stream ) { fwrite(buf, 1, strlen(buf), stream); fclose(stream); } }