/****************************************************************************** * The MIT License (MIT) * * Copyright (c) 2016-2017 Baldur Karlsson * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. ******************************************************************************/ #pragma once #include #include #include #include #include #include "RemoteHost.h" typedef QMap QStringMap; struct SPIRVDisassembler { SPIRVDisassembler() {} SPIRVDisassembler(const QVariant &var) { QVariantMap map = var.toMap(); if(map.contains("name")) name = map["name"].toString(); if(map.contains("executable")) executable = map["executable"].toString(); if(map.contains("args")) args = map["args"].toString(); } operator QVariant() const { QVariantMap map; map["name"] = name; map["executable"] = executable; map["args"] = args; return map; } QString name; QString executable; QString args; }; #define CONFIG_SETTING_VAL(access, variantType, type, name, defaultValue) \ access: \ type name = defaultValue; #define CONFIG_SETTING(access, variantType, type, name) \ access: \ type name; #define CONFIG_SETTINGS() \ \ CONFIG_SETTING_VAL(public, QString, QString, LastLogPath, "") \ \ CONFIG_SETTING(public, QVariantList, QList, RecentLogFiles) \ \ CONFIG_SETTING_VAL(public, QString, QString, LastCapturePath, "") \ \ CONFIG_SETTING_VAL(public, QString, QString, LastCaptureExe, "") \ \ CONFIG_SETTING(public, QVariantList, QList, RecentCaptureSettings) \ \ CONFIG_SETTING_VAL(public, int, int, CallstackLevelSkip, 0) \ \ CONFIG_SETTING_VAL(public, QString, QString, TemporaryCaptureDirectory, "") \ \ CONFIG_SETTING_VAL(public, QString, QString, DefaultCaptureSaveDirectory, "") \ \ CONFIG_SETTING_VAL(public, bool, bool, TextureViewer_ResetRange, false) \ \ CONFIG_SETTING_VAL(public, bool, bool, TextureViewer_PerTexSettings, true) \ \ CONFIG_SETTING_VAL(public, bool, bool, ShaderViewer_FriendlyNaming, true) \ \ CONFIG_SETTING_VAL(public, bool, bool, AlwaysReplayLocally, false) \ \ CONFIG_SETTING_VAL(public, int, int, LocalProxyAPI, -1) \ \ CONFIG_SETTING_VAL(public, int, TimeUnit, EventBrowser_TimeUnit, TimeUnit::Microseconds) \ \ CONFIG_SETTING_VAL(public, bool, bool, EventBrowser_HideEmpty, false) \ \ CONFIG_SETTING_VAL(public, bool, bool, EventBrowser_HideAPICalls, false) \ \ CONFIG_SETTING_VAL(public, bool, bool, EventBrowser_ApplyColours, true) \ \ CONFIG_SETTING_VAL(public, bool, bool, EventBrowser_ColourEventRow, true) \ \ CONFIG_SETTING_VAL(public, int, int, Formatter_MinFigures, 2) \ \ CONFIG_SETTING_VAL(public, int, int, Formatter_MaxFigures, 5) \ \ CONFIG_SETTING_VAL(public, int, int, Formatter_NegExp, 5) \ \ CONFIG_SETTING_VAL(public, int, int, Formatter_PosExp, 7) \ \ CONFIG_SETTING_VAL(public, bool, bool, Font_PreferMonospaced, false) \ \ CONFIG_SETTING_VAL(public, QString, QString, Android_AdbExecutablePath, "") \ \ CONFIG_SETTING_VAL(public, int, int, Android_MaxConnectTimeout, 30) \ \ CONFIG_SETTING_VAL(public, bool, bool, CheckUpdate_AllowChecks, true) \ \ CONFIG_SETTING_VAL(public, bool, bool, CheckUpdate_UpdateAvailable, false) \ \ CONFIG_SETTING_VAL(public, QString, QString, CheckUpdate_UpdateResponse, "") \ \ CONFIG_SETTING_VAL(public, QDateTime, QDateTime, CheckUpdate_LastUpdate, \ QDateTime(QDate(2012, 06, 27), QTime(0, 0, 0))) \ \ CONFIG_SETTING_VAL(public, QDateTime, QDateTime, DegradedLog_LastUpdate, \ QDateTime(QDate(2015, 01, 01), QTime(0, 0, 0))) \ \ CONFIG_SETTING_VAL(public, bool, bool, Tips_HasSeenFirst, false) \ \ CONFIG_SETTING_VAL(public, bool, bool, AllowGlobalHook, false) \ \ CONFIG_SETTING(public, QVariantList, QList, SPIRVDisassemblers) \ \ CONFIG_SETTING(private, QVariantMap, QStringMap, ConfigSettings) \ \ CONFIG_SETTING(private, QVariantList, QList, RemoteHostList) class PersistantConfig { public: enum class TimeUnit : int { Seconds = 0, Milliseconds, Microseconds, Nanoseconds, Count, }; // Runtime list of dynamically allocated hosts. // Saved to/from private RemoteHostList in CONFIG_SETTINGS() QList RemoteHosts; void AddAndroidHosts(); CONFIG_SETTINGS() public: PersistantConfig() {} ~PersistantConfig(); bool Load(const QString &filename); bool Save(); void SetupFormatting(); static QString UnitPrefix(TimeUnit t) { if(t == TimeUnit::Seconds) return "s"; else if(t == TimeUnit::Milliseconds) return "ms"; else if(t == TimeUnit::Microseconds) return "µs"; else if(t == TimeUnit::Nanoseconds) return "ns"; return "s"; } static void AddRecentFile(QList &recentList, const QString &file, int maxItems); void SetConfigSetting(const QString &name, const QString &value); QString GetConfigSetting(const QString &name); private: bool Deserialize(const QString &filename); bool Serialize(const QString &filename); QVariantMap storeValues() const; void applyValues(const QVariantMap &values); QString m_Filename; };