"Fossies" - the Fresh Open Source Software Archive

Member "rufus-3.13/src/settings.h" (20 Nov 2020, 5523 Bytes) of package /linux/misc/rufus-3.13.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "settings.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.12_vs_3.13.

    1 /*
    2  * Rufus: The Reliable USB Formatting Utility
    3  * Settings access, through either registry or INI file
    4  * Copyright © 2015-2019 Pete Batard <pete@akeo.ie>
    5  *
    6  * This program is free software: you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation, either version 3 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18  */
   19 #include <windows.h>
   20 #include <stdint.h>
   21 #include "rufus.h"
   22 #include "registry.h"
   23 
   24 #pragma once
   25 extern char* ini_file;
   26 
   27 /*
   28  * List of setting names used by this application
   29  */
   30 #define SETTING_ADVANCED_MODE               "AdvancedMode"
   31 #define SETTING_ADVANCED_MODE_DEVICE        "ShowAdvancedDriveProperties"
   32 #define SETTING_ADVANCED_MODE_FORMAT        "ShowAdvancedFormatOptions"
   33 #define SETTING_COMM_CHECK                  "CommCheck64"
   34 #define SETTING_DEFAULT_THREAD_PRIORITY     "DefaultThreadPriority"
   35 #define SETTING_DISABLE_FAKE_DRIVES_CHECK   "DisableFakeDrivesCheck"
   36 #define SETTING_DISABLE_LGP                 "DisableLGP"
   37 #define SETTING_DISABLE_SECURE_BOOT_NOTICE  "DisableSecureBootNotice"
   38 #define SETTING_DISABLE_VHDS                "DisableVHDs"
   39 #define SETTING_ENABLE_EXTRA_HASHES         "EnableExtraHashes"
   40 #define SETTING_ENABLE_FILE_INDEXING        "EnableFileIndexing"
   41 #define SETTING_ENABLE_USB_DEBUG            "EnableUsbDebug"
   42 #define SETTING_ENABLE_VMDK_DETECTION       "EnableVmdkDetection"
   43 #define SETTING_ENABLE_WIN_DUAL_EFI_BIOS    "EnableWindowsDualUefiBiosMode"
   44 #define SETTING_FORCE_LARGE_FAT32_FORMAT    "ForceLargeFat32Formatting"
   45 #define SETTING_IGNORE_BOOT_MARKER          "IgnoreBootMarker"
   46 #define SETTING_INCLUDE_BETAS               "CheckForBetas"
   47 #define SETTING_LAST_UPDATE                 "LastUpdateCheck"
   48 #define SETTING_LOCALE                      "Locale"
   49 #define SETTING_UPDATE_INTERVAL             "UpdateCheckInterval"
   50 #define SETTING_USE_EXT_VERSION             "UseExtVersion"
   51 #define SETTING_USE_PROPER_SIZE_UNITS       "UseProperSizeUnits"
   52 #define SETTING_USE_UDF_VERSION             "UseUdfVersion"
   53 #define SETTING_USE_VDS                     "UseVds"
   54 #define SETTING_PRESERVE_TIMESTAMPS         "PreserveTimestamps"
   55 #define SETTING_VERBOSE_UPDATES             "VerboseUpdateCheck"
   56 
   57 
   58 static __inline BOOL CheckIniKey(const char* key) {
   59     char* str = get_token_data_file(key, ini_file);
   60     BOOL ret = (str != NULL);
   61     safe_free(str);
   62     return ret;
   63 }
   64 #define CheckIniKey64 CheckIniKey
   65 #define CheckIniKey32 CheckIniKey
   66 #define CheckIniKeyBool CheckIniKey
   67 #define CheckIniKeyStr CheckIniKey
   68 
   69 static __inline int64_t ReadIniKey64(const char* key) {
   70     int64_t val = 0;
   71     char* str = get_token_data_file(key, ini_file);
   72     if (str != NULL) {
   73         val = _strtoi64(str, NULL, 0);
   74         free(str);
   75     }
   76     return val;
   77 }
   78 static __inline BOOL WriteIniKey64(const char* key, int64_t val) {
   79     char str[24];
   80     static_sprintf(str, "%" PRIi64, val);
   81     return (set_token_data_file(key, str, ini_file) != NULL);
   82 }
   83 
   84 static __inline int32_t ReadIniKey32(const char* key) {
   85     int32_t val = 0;
   86     char* str = get_token_data_file(key, ini_file);
   87     if (str != NULL) {
   88         val = strtol(str, NULL, 0);
   89         free(str);
   90     }
   91     return val;
   92 }
   93 static __inline BOOL WriteIniKey32(const char* key, int32_t val) {
   94     char str[12];
   95     static_sprintf(str, "%d", val);
   96     return (set_token_data_file(key, str, ini_file) != NULL);
   97 }
   98 
   99 static __inline char* ReadIniKeyStr(const char* key) {
  100     static char str[512];
  101     char* val;
  102     str[0] = 0;
  103     val = get_token_data_file(key, ini_file);
  104     if (val != NULL) {
  105         static_strcpy(str, val);
  106         free(val);
  107     }
  108     return str;
  109 }
  110 
  111 static __inline BOOL WriteIniKeyStr(const char* key, const char* val) {
  112     return (set_token_data_file(key, val, ini_file) != NULL);
  113 }
  114 
  115 /* Helpers for boolean operations */
  116 #define ReadIniKeyBool(key) (ReadIniKey32(key) != 0)
  117 #define WriteIniKeyBool(key, b) WriteIniKey32(key, (b)?1:0)
  118 
  119 /*
  120  * Read and store settings from/to ini file or registry
  121  */
  122 static __inline int64_t ReadSetting64(const char* key) {
  123     return (ini_file != NULL)?ReadIniKey64(key):ReadRegistryKey64(REGKEY_HKCU, key);
  124 }
  125 static __inline BOOL WriteSetting64(const char* key, int64_t val) {
  126     return (ini_file != NULL)?WriteIniKey64(key, val):WriteRegistryKey64(REGKEY_HKCU, key, val);
  127 }
  128 static __inline int32_t ReadSetting32(const char* key) {
  129     return (ini_file != NULL)?ReadIniKey32(key):ReadRegistryKey32(REGKEY_HKCU, key);
  130 }
  131 static __inline BOOL WriteSetting32(const char* key, int32_t val) {
  132     return (ini_file != NULL)?WriteIniKey32(key, val):WriteRegistryKey32(REGKEY_HKCU, key, val);
  133 }
  134 static __inline BOOL ReadSettingBool(const char* key) {
  135     return (ini_file != NULL)?ReadIniKeyBool(key):ReadRegistryKeyBool(REGKEY_HKCU, key);
  136 }
  137 static __inline BOOL WriteSettingBool(const char* key, BOOL val) {
  138     return (ini_file != NULL)?WriteIniKeyBool(key, val):WriteRegistryKeyBool(REGKEY_HKCU, key, val);
  139 }
  140 static __inline char* ReadSettingStr(const char* key) {
  141     return (ini_file != NULL)?ReadIniKeyStr(key):ReadRegistryKeyStr(REGKEY_HKCU, key);
  142 }
  143 static __inline BOOL WriteSettingStr(const char* key, char* val) {
  144     return (ini_file != NULL)?WriteIniKeyStr(key, val):WriteRegistryKeyStr(REGKEY_HKCU, key, val);
  145 }