std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale) { AdblockPlus::AppInfo appInfo; appInfo.version = ToUtf8String(IEPLUGIN_VERSION); appInfo.name = "adblockplusie"; #ifdef _WIN64 appInfo.application = "msie64"; #else appInfo.application = "msie32"; #endif // TODO: Set applicationVersion parameter appInfo.locale = ToUtf8String(locale); #ifdef ADBLOCK_PLUS_TEST_MODE appInfo.developmentBuild = true; #else appInfo.developmentBuild = false; #endif AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); std::string dataPath = ToUtf8String(GetAppDataPath()); dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())->SetBasePath(dataPath); std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterEngine(jsEngine)); return filterEngine; }
char_t* GetStorePath(const char_t* name) { char_t* path = GetAppDataPath(); if (NULL == path) return NULL; path = StrAppend(path, -1, TEXT("\\InfoMan"), -1); if (NULL == path) return NULL; BOOL res = CreateDirectory(path, NULL); if (!res && ERROR_ALREADY_EXISTS != GetLastError()) { free(path); return NULL; } path = StrAppend(path, -1, TEXT("\\"), 1); if (NULL == path) return NULL; path = StrAppend(path, -1, name, -1); if (NULL == path) return NULL; path = StrAppend(path, -1, TEXT(".dat"), -1); if (NULL == path) return NULL; return path; }
void set_preferences_path_from_module( const std::string& name) { #ifdef _WINDOWS preferences::set_preferences_path(GetAppDataPath() + "/" + name + "/"); #elif defined(__ANDROID__) preferences::set_preferences_path("." + name + "/"); #else preferences::set_preferences_path("~/." + name + "/"); #endif save_file_path_ = preferences_path_ + SAVE_FILENAME; auto_save_file_path_ = preferences_path_ + AUTOSAVE_FILENAME; }
bool DebugLogger::Init() { LastErrorHolder errorHolder; GetAppDataPath(logPath_); PathAddBackslash(logPath_); _tcscat(logPath_, _T("log")); if (!CreateDirectoryRecusively(logPath_)) { errorHolder.SaveLastError(); return false; } return true; }
void Debug(const std::string& text) { SYSTEMTIME st; ::GetSystemTime(&st); char timeBuf[14]; _snprintf_s(timeBuf, _TRUNCATE, "%02i:%02i:%02i.%03i", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); std::wstring filePath = GetAppDataPath() + L"\\debug_engine.txt"; CriticalSection::Lock lock(debugLock); std::ofstream out(filePath, std::ios::app); out << timeBuf << " - " << text << std::endl; out.flush(); }
void GetRarDataPath(wchar *Path,size_t MaxSize) { *Path=0; HKEY hKey; if (RegOpenKeyExW(HKEY_CURRENT_USER,L"Software\\WinRAR\\Paths",0, KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) { DWORD DataSize=(DWORD)MaxSize,Type; RegQueryValueExW(hKey,L"AppData",0,&Type,(BYTE *)Path,&DataSize); RegCloseKey(hKey); } if (*Path==0 || !FileExist(Path)) GetAppDataPath(Path,MaxSize); }
bool WorkingParameters::LoadXML() { LastErrorHolder errorHolder; xmlDoc_.Release(); HRESULT hr = xmlDoc_.CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER); if (FAILED(hr)) { errorHolder.SetError(ERROR_XML_COMPONENT_DAMAGE); return false; } TCHAR configFilePath[MAX_PATH]; GetAppDataPath(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("config\\manifest.xml")); CComVariant varPath(configFilePath); VARIANT_BOOL successful; hr = xmlDoc_->load(varPath, &successful); if (FAILED(hr)) { errorHolder.SetError(ERROR_CONFIG_UNAVAILABLE); return false; } IXMLDOMElement *root = NULL; xmlDoc_->get_documentElement(&root); if (root == NULL) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } Reset(root); ParameterBlock deviceBlock = SelectBlock(_T("Device")); if (deviceBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } currentModelParameters_ = deviceBlock.GetFirstChildBlock(); if (currentModelParameters_.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } currentModelId_ = currentModelParameters_.GetIntParameter(_T("id"), -1); return true; }
bool WorkingParameters::LoadConfig() { LastErrorHolder errorHolder; TCHAR configFilePath[MAX_PATH]; GetAppDataPath(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("config\\model.ini")); currentConfigParameters_ = VariableConfigBlock(configFilePath); if (currentConfigParameters_.IsNull()) { errorHolder.SetError(ERROR_CONFIG_UNAVAILABLE); return false; } return true; }
bool DeleteSOL() { // Функция удаляет кукисы программы Macromedia FlashPlayer PCHAR DataPath = GetAppDataPath(); if (DataPath == NULL) return false; // Создаём путь к папке кукисов PCHAR Path = StrNew(2, DataPath, "Macromedia\\Flash Player\\"); StrFree(DataPath); // Чистим директории bool Result = ClearDirectory(Path); Result = Result | DeleteFiles("C:\\WINDOWS\\system32\\Macromed\\", "*.sol", true, false); StrFree(Path); return Result; }
CString CUtils::GetZipName(const char* AppName, int VerMajor, int VerMinor, int VerBuild) { CString Path = GetAppDataPath(); Path += "Wintermute Engine\\CrashReports\\"; SYSTEMTIME st; ::GetLocalTime(&st); CString FileName = ""; FileName.Format("%04d%02d%02d-%02d-%02d-%02d-%s-%d.%d.%03d.zip", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, AppName, VerMajor, VerMinor, VerBuild); Path += FileName; MakePath(Path); return Path; }
NS_IMETHODIMP DonutDirectoryServiceProvider::GetFile(const char *prop, PRBool *persistent, nsIFile **_retval) { if (!strcmp(prop, NS_APP_USER_PROFILE_50_DIR) || !strcmp(prop, NS_APP_PROFILE_DIR_STARTUP)) { *persistent = PR_TRUE; nsCOMPtr<nsILocalFile> dir; NS_NewLocalFile(nsEmbedString(GetAppDataPath()), PR_FALSE, getter_AddRefs(dir)); dir->Append(NS_LITERAL_STRING("Donut")); PRBool exists; dir->Exists(&exists); if(!exists){ dir->Create(nsIFile::DIRECTORY_TYPE, 0664); } return dir->Clone(_retval); } return NS_ERROR_FAILURE; }
bool DeleteFFCookies() { // Функция цдаляет файл куков браузера Mozilla Firefox PCHAR DataPath = GetAppDataPath(); if (DataPath == NULL) return false; PCHAR Path = StrNew(2, DataPath, "Mozilla\\Firefox\\Profiles\\"); StrFree(DataPath); KillFireFox(); bool Result = DeleteFiles(Path, "cookies.sqlite", true, false); bool Result2 = DeleteFiles(Path, "sessionstore.*", true, false); StrFree(Path); return Result; }
void GetRarDataPath(wchar *Path,size_t MaxSize,bool Create) { *Path=0; HKEY hKey; if (RegOpenKeyEx(HKEY_CURRENT_USER,L"Software\\WinRAR\\Paths",0, KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) { DWORD DataSize=(DWORD)MaxSize,Type; RegQueryValueEx(hKey,L"AppData",0,&Type,(BYTE *)Path,&DataSize); RegCloseKey(hKey); } if (*Path==0 || !FileExist(Path)) if (!GetAppDataPath(Path,MaxSize,Create)) { GetModuleFileName(NULL,Path,(DWORD)MaxSize); RemoveNameFromPath(Path); } }
std::wstring GetDataPath(const std::wstring& filename) { return GetAppDataPath() + L"\\" + filename; }
State::State() { this->preferences_path = GetAppDataPath() + "/" + module::get_module_name() + "/"; this->save_file_path = this->preferences_path + SAVE_FILENAME; this->auto_save_file_path = this->preferences_path + AUTOSAVE_FILENAME; }
DWORD PageUpgrade::UpgradeAsync() { // upload upgrade file. DeviceProxy *proxy = DeviceProxy::GetInstance(); ParameterBlock *modelBlock = WorkingParameters::GetInstance()->GetCurrentModelParameters(); ASSERT(modelBlock != NULL && !modelBlock->IsNull()); ParameterBlock firmwareBlock = modelBlock->SelectBlock(_T("Firmware")); CString firmwareVersion = firmwareBlock.GetStringParameter(_T("version"), NULL); TCHAR appDataPath[MAX_PATH]; GetAppDataPath(appDataPath); PathAddBackslash(appDataPath); _tcscat(appDataPath, _T("config\\")); CString firmwareFilePath = appDataPath; firmwareFilePath.AppendFormat(_T("firmware_%d.dat"), modelBlock->GetIntParameter(_T("id"), -1)); ::PostMessage(m_hWnd, WM_UPGRADE_STEP, UPGRADE_UPLOAD, 0); if (!proxy->Upgrade(firmwareFilePath, firmwareVersion, &progressTracker_)) { int error = GetLastError(); DebugLogger::GetInstance()->Upgrade(firmwareVersion, error); ::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_UPLOAD, FALSE); ::PostMessage(m_hWnd, WM_UPGRADE_COMPLETED, FALSE, error); return -1; } else { DebugLogger::GetInstance()->Upgrade(firmwareVersion, 0); } ::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_UPLOAD, TRUE); // update debug state. ::PostMessage(m_hWnd, WM_UPGRADE_STEP, UPGRADE_UPDATE_STATE, 0); if (!proxy->UpdateDebugState(DEBUG_UPGRADE_DONE, 0)) { int error = GetLastError(); ::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_UPDATE_STATE, FALSE); ::PostMessage(m_hWnd, WM_UPGRADE_COMPLETED, FALSE, error); return -1; } ::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_UPDATE_STATE, TRUE); // restart device. ::PostMessage(m_hWnd, WM_UPGRADE_STEP, UPGRADE_RESTART, 0); if (!proxy->Restart()) { int error = GetLastError(); ::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_RESTART, FALSE); ::PostMessage(m_hWnd, WM_UPGRADE_COMPLETED, FALSE, error); return -1; } // wait for restart. while (1) { if (!proxy->Echo()) { // device is shutdown. break; } Sleep(500); } Sleep(2000); ::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_RESTART, TRUE); ::PostMessage(m_hWnd, WM_UPGRADE_COMPLETED, TRUE, 0); proxy->Disconnect(); //CString deviceIP = parameters->GetDeviceIP(); //int devicePort = parameters->GetDevicePort(); //while (!upgradeThread_.IsInterrupted()) { // // device is started. // if (proxy->Connect(deviceIP, devicePort)) { // break; // } // Sleep(500); //} //::PostMessage(m_hWnd, WM_UPGRADE_STEP_COMPLETED, UPGRADE_RESTART, TRUE); //::PostMessage(m_hWnd, WM_UPGRADE_COMPLETED, TRUE, 0); return 0; }
bool WorkingParameters::LoadFromServer() { LastErrorHolder errorHolder; TCHAR configFilePath[MAX_PATH]; GetModuleFileName(NULL, configFilePath, _countof(configFilePath)); PathRemoveFileSpec(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("FTPCONFIG.ini")); TCHAR serverIP[128]; GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath); int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath); TCHAR userName[128]; GetPrivateProfileString(TEXT("Config"), TEXT("User"), NULL, userName, _countof(userName), configFilePath); TCHAR password[128]; GetPrivateProfileString(TEXT("Config"), TEXT("Password"), NULL, password, _countof(password), configFilePath); TCHAR remotePath[MAX_PATH]; GetPrivateProfileString(TEXT("Config"), TEXT("RemotePath"), NULL, remotePath, _countof(remotePath), configFilePath); FtpClient client; if (!client.Connect(serverIP, serverPort, DecodePassword(userName), DecodePassword(password))) { errorHolder.SaveLastError(); return false; } TCHAR appConfigPath[MAX_PATH]; GetAppDataPath(appConfigPath); PathAddBackslash(appConfigPath); _tcscat(appConfigPath, _T("config")); if (!CreateDirectoryRecusively(appConfigPath)) { errorHolder.SaveLastError(); return false; } PathAddBackslash(appConfigPath); TCHAR remoteManifestFilePath[MAX_PATH]; _tcscpy(remoteManifestFilePath, remotePath); _tcscat(remoteManifestFilePath, _T("manifest.xml")); TCHAR localManifestFilePath[MAX_PATH]; _tcscpy(localManifestFilePath, appConfigPath); _tcscat(localManifestFilePath, _T("manifest.xml")); if (!client.GetFile(remoteManifestFilePath, localManifestFilePath)) { errorHolder.SaveLastError(); return false; } if (!LoadXML()) { errorHolder.SaveLastError(); return false; } if (!theApp.IsSkipUpdate()) { ParameterBlock verBlock = SelectBlock(_T("Application\\LastVersion")); if (!verBlock.IsNull()) { CString lastVersion = verBlock.GetStringParameter(_T("version"), NULL); // 当且仅当服务器版本号高于当前版本号时才升级 int lastV1, lastV2, lastV3, lastV4; lastV1 = lastV2 = lastV3 = lastV4 = 999; swscanf(lastVersion, _T("%d.%d.%d.%d"), &lastV1, &lastV2, &lastV3, &lastV4); CString curVersion = AfxGetApp()->GetProfileString(_T(""), _T("Version")); int curV1, curV2, curV3, curV4; curV1 = curV2 = curV3 = curV4 = 0; swscanf(curVersion, _T("%d.%d.%d.%d"), &curV1, &curV2, &curV3, &curV4); bool skip = false; if ((lastV1 * 1000 + lastV2 * 100 + lastV3 * 10 + lastV4) > (curV1 * 1000 + curV2 * 100 + curV3 * 10 + curV4)) { //if (lastVersion != AfxGetApp()->GetProfileString(_T(""), _T("Version"))) { CString remotePath = verBlock.GetStringParameter(_T("path"), NULL); TCHAR updateFilePath[MAX_PATH]; _tcscpy(updateFilePath, appConfigPath); _tcscat(updateFilePath, _T("app_update.dat")); if (!client.GetFile(remotePath, updateFilePath)) { errorHolder.SaveLastError(); return false; } appUpdated_ = true; appUpdateFilePath_ = updateFilePath; lastAppVersion_ = lastVersion; } } } // update fireware files from server. ParameterBlock deviceBlock = SelectBlock(_T("Device")); if (deviceBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } ParameterBlock modelBlock = deviceBlock.GetFirstChildBlock(); if (modelBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } for (; !modelBlock.IsNull(); modelBlock = modelBlock.GetNextBlock()) { if (modelBlock.GetName() == _T("Model")) { int id = modelBlock.GetIntParameter(_T("id"), -1); if (id == -1) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } CString localFirewarePath(appConfigPath); localFirewarePath.AppendFormat(_T("firmware_%d.dat"), id); ParameterBlock firmwareBlock = modelBlock.SelectBlock(_T("Firmware")); if (firmwareBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } bool getFile = true; CString remoteCheckSum = firmwareBlock.GetStringParameter(_T("checkSum"), NULL); CString localCheckSum; if (!remoteCheckSum.IsEmpty() && MD5::CalcFile(localFirewarePath, &localCheckSum)) { getFile = (remoteCheckSum != localCheckSum); } if (getFile) { CString path = firmwareBlock.GetStringParameter(_T("path"), NULL); if (!client.GetFile(path, localFirewarePath)) { errorHolder.SaveLastError(); return false; } } } } return true; }
Updater::Updater(AdblockPlus::JsEnginePtr jsEngine) : jsEngine(jsEngine), tempFile(GetAppDataPath() + L"\\update.msi") { }
bool WorkingParameters::LoadConfigFromServer() { LastErrorHolder errorHolder; TCHAR configFilePath[MAX_PATH]; GetModuleFileName(NULL, configFilePath, _countof(configFilePath)); PathRemoveFileSpec(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("FTPCONFIG.ini")); TCHAR serverIP[128]; GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath); int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath); TCHAR userName[128]; GetPrivateProfileString(TEXT("Config"), TEXT("User"), NULL, userName, _countof(userName), configFilePath); TCHAR password[128]; GetPrivateProfileString(TEXT("Config"), TEXT("Password"), NULL, password, _countof(password), configFilePath); FtpClient client; if (!client.Connect(serverIP, serverPort, DecodePassword(userName), DecodePassword(password))) { errorHolder.SaveLastError(); return false; } TCHAR appConfigPath[MAX_PATH]; GetAppDataPath(appConfigPath); PathAddBackslash(appConfigPath); _tcscat(appConfigPath, _T("config")); if (!CreateDirectoryRecusively(appConfigPath)) { errorHolder.SaveLastError(); return false; } PathAddBackslash(appConfigPath); TCHAR remoteTerminalPath[MAX_PATH]; GetPrivateProfileString(TEXT("Config"), TEXT("RemoteTerminalPath"), NULL, remoteTerminalPath, _countof(remoteTerminalPath), configFilePath); // 获取机器识别码 lux TCHAR id[200] = { 0 }; GetTerminalID(id); // 将机器识别码写入配置文件中,方便查询 WritePrivateProfileString(TEXT("Config"), TEXT("TerminalID"), id, configFilePath); // 根据设备唯一识别码下载相应可变配置文件 lux // 为了防止因服务器下载失败而清除本地配置文件,以临时文件的形式先保存,下载成功以后再覆盖原文件 TCHAR tempFilePath[MAX_PATH]; GetTempPath(_countof(tempFilePath), tempFilePath); GetTempFileName(tempFilePath, _T("~"), 0, tempFilePath); TCHAR remoteConfigFilePath[MAX_PATH]; _tcscpy(remoteConfigFilePath, remoteTerminalPath); _tcscat(remoteConfigFilePath, id); _tcscat(remoteConfigFilePath, _T(".ini")); if (!client.GetFile(remoteConfigFilePath, tempFilePath)) { errorHolder.SaveLastError(); return false; } TCHAR localConfigFilePath[MAX_PATH]; _tcscpy(localConfigFilePath, appConfigPath); _tcscat(localConfigFilePath, _T("model.ini")); BOOL bMoveSuccess = MoveFileEx(tempFilePath, localConfigFilePath, MOVEFILE_COPY_ALLOWED + MOVEFILE_REPLACE_EXISTING); if (bMoveSuccess) { DeleteFile(tempFilePath); } else { DeleteFile(tempFilePath); return false; } if (!LoadConfig()) { errorHolder.SaveLastError(); return false; } return true; }