//--------------------------------------------------------------------------- void TConfiguration::CleanupConfiguration() { try { CleanupRegistry(GetConfigurationSubKey()); if (GetStorage() == stRegistry) { FDontSave = true; } } catch (Exception &E) { throw ExtException(&E, LoadStr(CLEANUP_CONFIG_ERROR)); } }
//--------------------------------------------------------------------------- void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/, TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/) { if ((Button == mbRight) && Shift.Contains(ssAlt)) { try { ACCESS_VIOLATION_TEST; } catch (Exception & E) { throw ExtException(&E, MainInstructions(L"Internal error test.")); } } }
//--------------------------------------------------------------------------- void __fastcall TConfiguration::CleanupConfiguration() { try { CleanupRegistry(ConfigurationSubKey); if (Storage == stRegistry) { FDontSave = true; } } catch (Exception &E) { throw ExtException(&E, LoadStr(CLEANUP_CONFIG_ERROR)); } }
//--------------------------------------------------------------------------- void TConfiguration::CleanupRandomSeedFile() { try { DontSaveRandomSeed(); if (::FileExists(GetRandomSeedFileName())) { DeleteFileChecked(GetRandomSeedFileName()); } } catch (Exception &E) { throw ExtException(&E, LoadStr(CLEANUP_SEEDFILE_ERROR)); } }
UnicodeString TConfiguration::GetFileVersion(TVSFixedFileInfo * Info) { TGuard Guard(FCriticalSection); try { UnicodeString Result = FormatVersion( HIWORD(Info->dwFileVersionMS), LOWORD(Info->dwFileVersionMS), HIWORD(Info->dwFileVersionLS)); return Result; } catch (Exception &E) { throw ExtException(&E, L"Can't get file version"); } }
void TSessionLog::OpenLogFile() { DebugAssert(FConfiguration != nullptr); if (!FConfiguration) return; try { DebugAssert(FLogger == nullptr); FCurrentLogFileName = FConfiguration->GetLogFileName(); FILE *file = LocalOpenLogFile(FCurrentLogFileName, FStarted, FSessionData, FConfiguration->GetLogFileAppend(), FCurrentFileName); FLogger = new tinylog::TinyLog(file); TSearchRec SearchRec; if (FileSearchRec(FCurrentFileName, SearchRec)) { FCurrentFileSize = SearchRec.Size; } else { FCurrentFileSize = 0; } } catch (Exception &E) { // We failed logging to file, turn it off and notify user. FCurrentLogFileName.Clear(); FCurrentFileName.Clear(); FConfiguration->SetLogFileName(UnicodeString()); try { throw ExtException(&E, LoadStr(LOG_GEN_ERROR)); } catch (Exception &E2) { AddException(&E2); // not to deadlock with TSessionLog::ReflectSettings invoked by FConfiguration->LogFileName setter above TUnguard Unguard(FCriticalSection); FUI->HandleExtendedException(&E2); } } // in case we are appending and the existing log file is already too large if (FLogger != nullptr) { CheckSize(0); } }
//--------------------------------------------------------------------------- UnicodeString __fastcall TConfiguration::GetVersionStr() { TGuard Guard(FCriticalSection); try { TVSFixedFileInfo * Info = FixedApplicationInfo; return FMTLOAD(VERSION, ( HIWORD(Info->dwFileVersionMS), LOWORD(Info->dwFileVersionMS), HIWORD(Info->dwFileVersionLS), LOWORD(Info->dwFileVersionLS))); } catch (Exception &E) { throw ExtException(&E, L"Can't get application version"); } }
//--------------------------------------------------------------------------- UnicodeString __fastcall TConfiguration::GetVersion() { TGuard Guard(FCriticalSection); try { TVSFixedFileInfo * Info = FixedApplicationInfo; UnicodeString Result; Result = TrimVersion(FORMAT(L"%d.%d.%d", ( HIWORD(Info->dwFileVersionMS), LOWORD(Info->dwFileVersionMS), HIWORD(Info->dwFileVersionLS)))); return Result; } catch (Exception &E) { throw ExtException(&E, L"Can't get application version"); } }
//--------------------------------------------------------------------------- void __fastcall TConfiguration::CleanupIniFile() { try { if (FileExists(IniFileStorageNameForReading)) { DeleteFileChecked(IniFileStorageNameForReading); } if (Storage == stIniFile) { FDontSave = true; } } catch (Exception &E) { throw ExtException(&E, LoadStr(CLEANUP_INIFILE_ERROR)); } }
//--------------------------------------------------------------------------- void TSessionLog::Add(TLogLineType Type, const UnicodeString & Line) { assert(FConfiguration); if (GetLogging()) { try { if (FParent != nullptr) { DoAdd(Type, Line, MAKE_CALLBACK(TSessionLog::DoAddToParent, this)); } else { TGuard Guard(FCriticalSection); BeginUpdate(); auto cleanup = finally([&]() { DeleteUnnecessary(); EndUpdate(); }); { DoAdd(Type, Line, MAKE_CALLBACK(TSessionLog::DoAddToSelf, this)); } } } catch (Exception &E) { // We failed logging, turn it off and notify user. FConfiguration->SetLogging(false); try { throw ExtException(&E, LoadStr(LOG_GEN_ERROR)); } catch (Exception &E) { AddException(&E); FUI->HandleExtendedException(&E); } } } }
void TConfiguration::CleanupIniFile() { #if 0 try { if (::FileExists(ApiPath(GetIniFileStorageNameForReading()))) { DeleteFileChecked(GetIniFileStorageNameForReading()); } if (GetStorage() == stIniFile) { FDontSave = true; } } catch (Exception & E) { throw ExtException(&E, LoadStr(CLEANUP_INIFILE_ERROR)); } #endif }
UnicodeString TConfiguration::GetProductVersion() const { TGuard Guard(FCriticalSection); UnicodeString Result; try { TVSFixedFileInfo * Info = GetFixedApplicationInfo(); if (Info) { Result = FormatVersion( HIWORD(Info->dwFileVersionMS), LOWORD(Info->dwFileVersionMS), HIWORD(Info->dwFileVersionLS)); } } catch (Exception & E) { throw ExtException(&E, "Can't get application version"); } return Result; }
void RethrowException(Exception * E) { // this list has to be in sync with ExceptionMessage if (NB_STATIC_DOWNCAST(EFatal, E) != nullptr) { throw EFatal(E, L""); } else if (NB_STATIC_DOWNCAST(ECallbackGuardAbort, E) != nullptr) { throw ECallbackGuardAbort(); } else if (NB_STATIC_DOWNCAST(EAbort, E) != nullptr) { throw EAbort(E->Message); } else if (WellKnownException(E, nullptr, nullptr, nullptr, true)) { // noop, should never get here } else { throw ExtException(E, L""); } }
void RethrowException(Exception * E) { // this list has to be in sync with ExceptionMessage if (isa<EFatal>(E)) { throw EFatal(E, L""); } else if (isa<ECallbackGuardAbort>(E)) { throw ECallbackGuardAbort(); } else if (isa<EAbort>(E)) { throw EAbort(E->Message); } else if (WellKnownException(E, nullptr, nullptr, nullptr, true)) { // noop, should never get here } else { throw ExtException(E, L""); } }
UnicodeString TConfiguration::GetProductVersionStr() const { UnicodeString Result; #ifndef __linux__ TGuard Guard(FCriticalSection); try { TVSFixedFileInfo * Info = GetFixedApplicationInfo(); /*return FMTLOAD(VERSION, HIWORD(Info->dwFileVersionMS), LOWORD(Info->dwFileVersionMS), HIWORD(Info->dwFileVersionLS), LOWORD(Info->dwFileVersionLS));*/ UnicodeString BuildStr; if (!GetIsUnofficial()) { BuildStr = LoadStr(VERSION_BUILD); } else { #ifdef _DEBUG BuildStr = LoadStr(VERSION_DEBUG_BUILD); #else BuildStr = LoadStr(VERSION_DEV_BUILD); #endif } int Build = LOWORD(Info->dwFileVersionLS); if (Build > 0) { BuildStr += L" " + ::IntToStr(Build); } #if 0 #ifndef BUILD_OFFICIAL UnicodeString BuildDate = __DATE__; UnicodeString MonthStr = CutToChar(BuildDate, L' ', true); int Month = ParseShortEngMonthName(MonthStr); int Day = StrToInt64(CutToChar(BuildDate, L' ', true)); int Year = StrToInt64(Trim(BuildDate)); UnicodeString DateStr = FORMAT("%d-%2.2d-%2.2d", Year, Month, Day); AddToList(BuildStr, DateStr, L" "); #endif #endif UnicodeString FullVersion = GetProductVersion(); UnicodeString AReleaseType = GetReleaseType(); if (DebugAlwaysTrue(!AReleaseType.IsEmpty()) && !SameText(AReleaseType, L"stable") && !SameText(AReleaseType, L"development")) { FullVersion += L" " + AReleaseType; } Result = FMTLOAD(VERSION2, GetProductVersion().c_str(), Build); #if 0 #ifndef BUILD_OFFICIAL Result += L" " + LoadStr(VERSION_DONT_DISTRIBUTE); #endif #endif } catch (Exception & E) { throw ExtException(&E, "Can't get application version"); } #endif return Result; }
//--------------------------------------------------------------------------- void Error(int ErrorID, intptr_t data) { UnicodeString Msg = FMTLOAD(ErrorID, data); throw ExtException((Exception *)nullptr, Msg); }
void TActionLog::Add(UnicodeString Line) { DebugAssert(FConfiguration); if (FLogging) { TGuard Guard(FCriticalSection); if (FLogger == nullptr) { OpenLogFile(); } if (FLogger != nullptr) { try { UTF8String UtfLine = UTF8String(Line); size_t Written = FLogger->Write(UtfLine.c_str(), UtfLine.Length()); if (Written != static_cast<size_t>(UtfLine.Length())) { throw ECRTExtException(L""); } Written = FLogger->Write("\n", 1); if (Written != 1) { throw ECRTExtException(L""); } } catch (Exception &E) { // FCriticalSection.Release(); // avoid endless loop when trying to close tags when closing log, when logging has failed if (!FFailed) { FFailed = true; // We failed logging, turn it off and notify user. FConfiguration->SetLogActions(false); if (FConfiguration->GetLogActionsRequired()) { throw EFatal(&E, LoadStr(LOG_FATAL_ERROR)); } else { try { throw ExtException(&E, LoadStr(LOG_GEN_ERROR)); } catch (Exception &E2) { if (FUI != nullptr) { FUI->HandleExtendedException(&E2); } } } } } } } }
void Error(intptr_t Id, intptr_t ErrorId) { UnicodeString Msg = FMTLOAD(Id, ErrorId); throw ExtException(static_cast<Exception *>(nullptr), Msg); }
//--------------------------------------------------------------------------- IShellLink * __fastcall CreateDesktopShortCut(const UnicodeString & Name, const UnicodeString &File, const UnicodeString & Params, const UnicodeString & Description, int SpecialFolder, int IconIndex, bool Return) { IShellLink* pLink = NULL; if (SpecialFolder < 0) { SpecialFolder = CSIDL_DESKTOPDIRECTORY; } try { if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &pLink))) { try { pLink->SetPath(File.c_str()); pLink->SetDescription(Description.c_str()); pLink->SetArguments(Params.c_str()); pLink->SetShowCmd(SW_SHOW); // Explicitly setting icon file, // without this icons are not shown at least in Windows 7 jumplist pLink->SetIconLocation(File.c_str(), IconIndex); IPersistFile* pPersistFile; if (!Return && SUCCEEDED(pLink->QueryInterface(IID_IPersistFile, (void **)&pPersistFile))) { try { LPMALLOC ShellMalloc; LPITEMIDLIST DesktopPidl; wchar_t DesktopDir[MAX_PATH]; OleCheck(SHGetMalloc(&ShellMalloc)); try { OleCheck(SHGetSpecialFolderLocation(NULL, SpecialFolder, &DesktopPidl)); OleCheck(SHGetPathFromIDList(DesktopPidl, DesktopDir)); } __finally { ShellMalloc->Free(DesktopPidl); ShellMalloc->Release(); } WideString strShortCutLocation(DesktopDir); // Name can contain even path (e.g. to create quick launch icon) strShortCutLocation += UnicodeString(L"\\") + Name + L".lnk"; OleCheck(pPersistFile->Save(strShortCutLocation.c_bstr(), TRUE)); } __finally { pPersistFile->Release(); } } // this is necessary for Windows 7 taskbar jump list links IPropertyStore * PropertyStore; if (SUCCEEDED(pLink->QueryInterface(IID_IPropertyStore, (void**)&PropertyStore))) { PROPVARIANT Prop; Prop.vt = VT_LPWSTR; Prop.pwszVal = Name.c_str(); PropertyStore->SetValue(PKEY_Title, Prop); PropertyStore->Commit(); PropertyStore->Release(); } } catch(...) { pLink->Release(); throw; } if (!Return) { pLink->Release(); pLink = NULL; } } } catch(Exception & E) { throw ExtException(&E, LoadStr(CREATE_SHORTCUT_ERROR)); } return pLink; }
void Error(int ErrorID, intptr_t data) { UnicodeString Msg = FMTLOAD(ErrorID, data); throw ExtException(static_cast<Exception *>(nullptr), Msg); }