/* Caller needs to free() the result. */ WCHAR *AppGenDataFilename(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% */ WCHAR dir[MAX_PATH]; dir[0] = '\0'; BOOL ok = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, TRUE); if (ok) { path.Set(path::Join(dir, 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) { 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); }
static INT_PTR CALLBACK Dialog_Settings_Proc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { GlobalPrefs *prefs; switch (msg) { case WM_INITDIALOG: prefs = (GlobalPrefs *)lParam; assert(prefs); SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR)prefs); // Fill the page layouts into the select box SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Automatic")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Single Page")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Facing")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Book View")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Continuous")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Continuous Facing")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_ADDSTRING, 0, (LPARAM)_TR("Continuous Book View")); SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_SETCURSEL, prefs->defaultDisplayModeEnum - DM_FIRST, 0); SetupZoomComboBox(hDlg, IDC_DEFAULT_ZOOM, false, prefs->defaultZoomFloat); CheckDlgButton(hDlg, IDC_DEFAULT_SHOW_TOC, prefs->showToc ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT, prefs->rememberStatePerDocument ? BST_CHECKED : BST_UNCHECKED); EnableWindow(GetDlgItem(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT), prefs->rememberOpenedFiles); CheckDlgButton(hDlg, IDC_USE_SYS_COLORS, prefs->useSysColors ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_CHECK_FOR_UPDATES, prefs->checkForUpdates ? BST_CHECKED : BST_UNCHECKED); EnableWindow(GetDlgItem(hDlg, IDC_CHECK_FOR_UPDATES), HasPermission(Perm_InternetAccess)); CheckDlgButton(hDlg, IDC_REMEMBER_OPENED_FILES, prefs->rememberOpenedFiles ? BST_CHECKED : BST_UNCHECKED); if (IsExeAssociatedWithPdfExtension()) { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("SumatraPDF is your default PDF reader")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), FALSE); } else if (IsRunningInPortableMode()) { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("Default PDF reader can't be changed in portable mode")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), FALSE); } else { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("Make SumatraPDF my default PDF reader")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), HasPermission(Perm_RegistryAccess)); } win::SetText(hDlg, _TR("SumatraPDF Options")); SetDlgItemText(hDlg, IDC_SECTION_VIEW, _TR("View")); SetDlgItemText(hDlg, IDC_DEFAULT_LAYOUT_LABEL, _TR("Default &Layout:")); SetDlgItemText(hDlg, IDC_DEFAULT_ZOOM_LABEL, _TR("Default &Zoom:")); SetDlgItemText(hDlg, IDC_DEFAULT_SHOW_TOC, _TR("Show the &bookmarks sidebar when available")); SetDlgItemText(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT, _TR("&Remember these settings for each document")); SetDlgItemText(hDlg, IDC_USE_SYS_COLORS, _TR("Replace document &colors with Windows color scheme")); SetDlgItemText(hDlg, IDC_SECTION_ADVANCED, _TR("Advanced")); SetDlgItemText(hDlg, IDC_CHECK_FOR_UPDATES, _TR("Automatically check for &updates")); SetDlgItemText(hDlg, IDC_REMEMBER_OPENED_FILES, _TR("Remember &opened files")); SetDlgItemText(hDlg, IDC_SECTION_INVERSESEARCH, _TR("Set inverse search command-line")); SetDlgItemText(hDlg, IDC_CMDLINE_LABEL, _TR("Enter the command-line to invoke when you double-click on the PDF document:")); SetDlgItemText(hDlg, IDOK, _TR("OK")); SetDlgItemText(hDlg, IDCANCEL, _TR("Cancel")); if (GetSysColor(COLOR_WINDOWTEXT) == RGB(0, 0, 0) && GetSysColor(COLOR_WINDOW) == RGB(0xFF, 0xFF, 0xFF)) { // remove the "use system colors" item if it wouldn't change anything RemoveDialogItem(hDlg, IDC_USE_SYS_COLORS); } if (prefs->enableTeXEnhancements && HasPermission(Perm_DiskAccess)) { // Fill the combo with the list of possible inverse search commands // Try to select a correct default when first showing this dialog const WCHAR *cmdLine = prefs->inverseSearchCmdLine; ScopedMem<WCHAR> inverseSearch; if (!cmdLine) { inverseSearch.Set(AutoDetectInverseSearchCommands(GetDlgItem(hDlg, IDC_CMDLINE))); cmdLine = inverseSearch; } // Find the index of the active command line LRESULT ind = SendMessage(GetDlgItem(hDlg, IDC_CMDLINE), CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM) cmdLine); if (CB_ERR == ind) { // if no existing command was selected then set the user custom command in the combo ComboBox_AddItemData(GetDlgItem(hDlg, IDC_CMDLINE), cmdLine); SetDlgItemText(hDlg, IDC_CMDLINE, cmdLine); } else { // select the active command SendMessage(GetDlgItem(hDlg, IDC_CMDLINE), CB_SETCURSEL, (WPARAM) ind , 0); } } else { RemoveDialogItem(hDlg, IDC_SECTION_INVERSESEARCH, IDC_SECTION_ADVANCED); } CenterDialog(hDlg); SetFocus(GetDlgItem(hDlg, IDC_DEFAULT_LAYOUT)); return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: prefs = (GlobalPrefs *)GetWindowLongPtr(hDlg, GWLP_USERDATA); assert(prefs); prefs->defaultDisplayModeEnum = (DisplayMode)(SendDlgItemMessage(hDlg, IDC_DEFAULT_LAYOUT, CB_GETCURSEL, 0, 0) + DM_FIRST); prefs->defaultZoomFloat = GetZoomComboBoxValue(hDlg, IDC_DEFAULT_ZOOM, false, prefs->defaultZoomFloat); prefs->showToc = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_DEFAULT_SHOW_TOC)); prefs->rememberStatePerDocument = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT)); prefs->useSysColors = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_USE_SYS_COLORS)); prefs->checkForUpdates = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_CHECK_FOR_UPDATES)); prefs->rememberOpenedFiles = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_REMEMBER_OPENED_FILES)); if (prefs->enableTeXEnhancements && HasPermission(Perm_DiskAccess)) { free(prefs->inverseSearchCmdLine); prefs->inverseSearchCmdLine = win::GetText(GetDlgItem(hDlg, IDC_CMDLINE)); } EndDialog(hDlg, IDOK); return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; case IDC_REMEMBER_OPENED_FILES: { bool rememberOpenedFiles = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_REMEMBER_OPENED_FILES)); EnableWindow(GetDlgItem(hDlg, IDC_REMEMBER_STATE_PER_DOCUMENT), rememberOpenedFiles); } return TRUE; case IDC_DEFAULT_SHOW_TOC: case IDC_REMEMBER_STATE_PER_DOCUMENT: case IDC_CHECK_FOR_UPDATES: return TRUE; case IDC_SET_DEFAULT_READER: if (!HasPermission(Perm_RegistryAccess)) return TRUE; AssociateExeWithPdfExtension(); if (IsExeAssociatedWithPdfExtension()) { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("SumatraPDF is your default PDF reader")); EnableWindow(GetDlgItem(hDlg, IDC_SET_DEFAULT_READER), FALSE); SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hDlg, IDOK), TRUE); } else { SetDlgItemText(hDlg, IDC_SET_DEFAULT_READER, _TR("SumatraPDF should now be your default PDF reader")); } return TRUE; } break; } return FALSE; }