2020-01-13 01:44:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
|
2023-12-19 19:29:17 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-01-13 01:44:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-01-02 15:47:06 +00:00
|
|
|
#include <set>
|
2022-09-26 01:08:51 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
2021-05-01 17:39:35 +00:00
|
|
|
|
2024-01-16 22:20:45 +00:00
|
|
|
#include <env_vars.h>
|
2021-05-01 17:39:35 +00:00
|
|
|
#include <paths.h>
|
|
|
|
#include <search_stack.h>
|
2022-09-26 01:08:51 +00:00
|
|
|
#include <settings/settings_manager.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/common_settings.h>
|
2021-06-04 03:52:50 +00:00
|
|
|
#include <settings/json_settings_internals.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/parameters.h>
|
2021-05-01 17:39:35 +00:00
|
|
|
#include <systemdirsappend.h>
|
|
|
|
#include <trace_helpers.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <wx/config.h>
|
|
|
|
#include <wx/log.h>
|
2022-11-10 11:19:55 +00:00
|
|
|
#include <wx/regex.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
|
2021-01-02 15:47:06 +00:00
|
|
|
///! The following environment variables will never be migrated from a previous version
|
2024-01-16 22:20:45 +00:00
|
|
|
const wxRegEx versionedEnvVarRegex( wxS( "KICAD[0-9]+_[A-Z0-9_]+(_DIR)?" ) );
|
2021-01-02 15:47:06 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
///! Update the schema version whenever a migration is required
|
2022-09-26 01:08:51 +00:00
|
|
|
const int commonSchemaVersion = 3;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
COMMON_SETTINGS::COMMON_SETTINGS() :
|
|
|
|
JSON_SETTINGS( "kicad_common", SETTINGS_LOC::USER, commonSchemaVersion ),
|
2020-07-18 22:56:39 +00:00
|
|
|
m_Appearance(),
|
|
|
|
m_Backup(),
|
|
|
|
m_Env(),
|
|
|
|
m_Input(),
|
|
|
|
m_Graphics(),
|
2020-09-16 10:27:46 +00:00
|
|
|
m_Session(),
|
2021-02-24 19:32:34 +00:00
|
|
|
m_System(),
|
2021-12-30 23:42:06 +00:00
|
|
|
m_DoNotShowAgain(),
|
|
|
|
m_NetclassPanel(),
|
|
|
|
m_PackageManager()
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
2021-09-16 22:45:28 +00:00
|
|
|
/*
|
|
|
|
* Automatic dark mode detection works fine on Mac.
|
|
|
|
*/
|
|
|
|
#if defined( __WXGTK__ ) || defined( __WXMSW__ )
|
|
|
|
m_params.emplace_back( new PARAM_ENUM<ICON_THEME>( "appearance.icon_theme",
|
|
|
|
&m_Appearance.icon_theme, ICON_THEME::AUTO, ICON_THEME::LIGHT, ICON_THEME::AUTO ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
#else
|
2021-09-16 22:45:28 +00:00
|
|
|
m_Appearance.icon_theme = ICON_THEME::AUTO;
|
2020-01-13 01:44:19 +00:00
|
|
|
#endif
|
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
/*
|
2021-12-09 23:36:44 +00:00
|
|
|
* Automatic canvas scaling works fine on all supported platforms, so it's no longer exposed as
|
|
|
|
* a configuration option.
|
2021-09-16 22:45:28 +00:00
|
|
|
*/
|
|
|
|
m_Appearance.canvas_scale = 0.0;
|
2021-03-09 22:47:24 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
/*
|
|
|
|
* Menu icons are off by default on OSX and on for all other platforms.
|
|
|
|
*/
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "appearance.use_icons_in_menus",
|
|
|
|
&m_Appearance.use_icons_in_menus, false ) );
|
|
|
|
#else
|
2020-01-13 01:44:19 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "appearance.use_icons_in_menus",
|
2021-09-16 22:45:28 +00:00
|
|
|
&m_Appearance.use_icons_in_menus, true ) );
|
|
|
|
#endif
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
/*
|
|
|
|
* Font scaling hacks are only needed on GTK under wxWidgets 3.0.
|
|
|
|
*/
|
|
|
|
m_Appearance.apply_icon_scale_to_fonts = false;
|
2021-09-16 17:29:29 +00:00
|
|
|
|
2022-08-21 12:39:55 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "appearance.show_scrollbars",
|
2023-02-11 13:39:09 +00:00
|
|
|
&m_Appearance.show_scrollbars, false ) );
|
2022-08-21 12:39:55 +00:00
|
|
|
|
2021-11-05 23:35:10 +00:00
|
|
|
m_params.emplace_back( new PARAM<double>( "appearance.hicontrast_dimming_factor",
|
|
|
|
&m_Appearance.hicontrast_dimming_factor, 0.8f ) );
|
|
|
|
|
2022-01-23 23:04:19 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "appearance.text_editor_zoom",
|
|
|
|
&m_Appearance.text_editor_zoom, 0 ) );
|
|
|
|
|
2023-10-22 00:41:02 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "appearance.toolbar_icon_size",
|
|
|
|
&m_Appearance.toolbar_icon_size, 24, 16, 64 ) );
|
|
|
|
|
2020-07-03 13:40:31 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "auto_backup.enabled", &m_Backup.enabled, true ) );
|
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "auto_backup.backup_on_autosave",
|
|
|
|
&m_Backup.backup_on_autosave, false ) );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "auto_backup.limit_total_files",
|
|
|
|
&m_Backup.limit_total_files, 25 ) );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<unsigned long long>( "auto_backup.limit_total_size",
|
|
|
|
&m_Backup.limit_total_size, 104857600 ) );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "auto_backup.limit_daily_files",
|
|
|
|
&m_Backup.limit_daily_files, 5 ) );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "auto_backup.min_interval",
|
|
|
|
&m_Backup.min_interval, 300 ) );
|
2020-07-03 13:40:31 +00:00
|
|
|
|
2021-05-01 17:39:35 +00:00
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "environment.vars",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = {};
|
|
|
|
|
|
|
|
for( const std::pair<wxString, ENV_VAR_ITEM> entry : m_Env.vars )
|
|
|
|
{
|
|
|
|
const ENV_VAR_ITEM& var = entry.second;
|
|
|
|
|
|
|
|
wxASSERT( entry.first == var.GetKey() );
|
|
|
|
|
|
|
|
// Default values are never persisted
|
|
|
|
if( var.IsDefault() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceEnvVars,
|
2023-01-22 14:41:33 +00:00
|
|
|
wxS( "COMMON_SETTINGS: Env var %s skipping save (default)" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
var.GetKey() );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString value = var.GetValue();
|
|
|
|
|
|
|
|
// Vars that existed in JSON are persisted, but if they were overridden
|
|
|
|
// externally, we persist the old value (i.e. the one that was loaded from JSON)
|
|
|
|
if( var.GetDefinedExternally() )
|
|
|
|
{
|
|
|
|
if( var.GetDefinedInSettings() )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceEnvVars,
|
2023-12-19 19:29:17 +00:00
|
|
|
wxS( "COMMON_SETTINGS: Env var %s was overridden "
|
|
|
|
"externally, saving previously-loaded value %s" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
var.GetKey(), var.GetSettingsValue() );
|
|
|
|
value = var.GetSettingsValue();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogTrace( traceEnvVars,
|
2023-12-19 19:29:17 +00:00
|
|
|
wxS( "COMMON_SETTINGS: Env var %s skipping save "
|
|
|
|
"(external)" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
var.GetKey() );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxLogTrace( traceEnvVars,
|
2023-01-22 14:41:33 +00:00
|
|
|
wxS( "COMMON_SETTINGS: Saving env var %s = %s" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
var.GetKey(), value);
|
|
|
|
|
|
|
|
std::string key( var.GetKey().ToUTF8() );
|
2023-12-18 17:01:27 +00:00
|
|
|
ret[ std::move( key ) ] = value;
|
2021-05-01 17:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_object() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( const auto& entry : aJson.items() )
|
|
|
|
{
|
|
|
|
wxString key = wxString( entry.key().c_str(), wxConvUTF8 );
|
|
|
|
wxString val = entry.value().get<wxString>();
|
|
|
|
|
|
|
|
if( m_Env.vars.count( key ) )
|
|
|
|
{
|
|
|
|
if( m_Env.vars[key].GetDefinedExternally() )
|
|
|
|
{
|
2023-12-19 19:29:17 +00:00
|
|
|
wxLogTrace( traceEnvVars,
|
|
|
|
wxS( "COMMON_SETTINGS: %s is defined externally" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
key );
|
|
|
|
m_Env.vars[key].SetDefinedInSettings();
|
|
|
|
m_Env.vars[key].SetSettingsValue( val );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-19 19:29:17 +00:00
|
|
|
wxLogTrace( traceEnvVars,
|
|
|
|
wxS( "COMMON_SETTINGS: Updating %s: %s -> %s"),
|
2021-05-01 17:39:35 +00:00
|
|
|
key, m_Env.vars[key].GetValue(), val );
|
|
|
|
m_Env.vars[key].SetValue( val );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-19 19:29:17 +00:00
|
|
|
wxLogTrace( traceEnvVars,
|
|
|
|
wxS( "COMMON_SETTINGS: Loaded new var: %s = %s" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
key, val );
|
|
|
|
m_Env.vars[key] = ENV_VAR_ITEM( key, val );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Env.vars[key].SetDefinedInSettings();
|
|
|
|
m_Env.vars[key].SetSettingsValue( val );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{} ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2022-09-30 18:32:06 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.focus_follow_sch_pcb",
|
|
|
|
&m_Input.focus_follow_sch_pcb, false ) );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.auto_pan", &m_Input.auto_pan, false ) );
|
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "input.auto_pan_acceleration",
|
|
|
|
&m_Input.auto_pan_acceleration, 5 ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.center_on_zoom",
|
|
|
|
&m_Input.center_on_zoom, true ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.immediate_actions",
|
|
|
|
&m_Input.immediate_actions, true ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.warp_mouse_on_move",
|
|
|
|
&m_Input.warp_mouse_on_move, true ) );
|
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.horizontal_pan",
|
|
|
|
&m_Input.horizontal_pan, false ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2023-05-31 02:06:49 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.hotkey_feedback",
|
|
|
|
&m_Input.hotkey_feedback, true ) );
|
|
|
|
|
2021-01-11 15:49:09 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.zoom_acceleration",
|
2021-03-21 23:46:23 +00:00
|
|
|
&m_Input.zoom_acceleration, false ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
int default_zoom_speed = 5;
|
|
|
|
#else
|
|
|
|
int default_zoom_speed = 1;
|
|
|
|
#endif
|
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "input.zoom_speed",
|
|
|
|
&m_Input.zoom_speed, default_zoom_speed ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.zoom_speed_auto",
|
|
|
|
&m_Input.zoom_speed_auto, true ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_zoom",
|
|
|
|
&m_Input.scroll_modifier_zoom, 0 ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_pan_h",
|
|
|
|
&m_Input.scroll_modifier_pan_h, WXK_CONTROL ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "input.scroll_modifier_pan_v",
|
|
|
|
&m_Input.scroll_modifier_pan_v, WXK_SHIFT ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2023-08-17 19:17:50 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "input.reverse_scroll_pan_h",
|
|
|
|
&m_Input.reverse_scroll_pan_h, false ) );
|
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "input.mouse_left",
|
|
|
|
&m_Input.drag_left, MOUSE_DRAG_ACTION::DRAG_SELECTED, MOUSE_DRAG_ACTION::DRAG_ANY,
|
|
|
|
MOUSE_DRAG_ACTION::SELECT ) );
|
2021-01-11 11:48:51 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "input.mouse_middle",
|
|
|
|
&m_Input.drag_middle, MOUSE_DRAG_ACTION::PAN, MOUSE_DRAG_ACTION::SELECT,
|
|
|
|
MOUSE_DRAG_ACTION::NONE ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-01-11 15:46:41 +00:00
|
|
|
m_params.emplace_back( new PARAM_ENUM<MOUSE_DRAG_ACTION>( "input.mouse_right",
|
|
|
|
&m_Input.drag_right, MOUSE_DRAG_ACTION::PAN, MOUSE_DRAG_ACTION::SELECT,
|
|
|
|
MOUSE_DRAG_ACTION::NONE ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "graphics.opengl_antialiasing_mode",
|
2023-01-04 01:59:50 +00:00
|
|
|
&m_Graphics.opengl_aa_mode, 1, 0, 2 ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<int>( "graphics.cairo_antialiasing_mode",
|
2021-06-09 00:20:41 +00:00
|
|
|
&m_Graphics.cairo_aa_mode, 0, 0, 2 ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<int>( "system.autosave_interval",
|
|
|
|
&m_System.autosave_interval, 600 ) );
|
|
|
|
|
2021-09-19 13:45:27 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "system.text_editor",
|
2023-01-22 14:41:33 +00:00
|
|
|
&m_System.text_editor, wxS( "/usr/bin/open -e" ) ) );
|
2021-09-19 13:45:27 +00:00
|
|
|
#else
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "system.text_editor",
|
2023-01-22 14:41:33 +00:00
|
|
|
&m_System.text_editor, wxS( "" ) ) );
|
2021-09-19 13:45:27 +00:00
|
|
|
#endif
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<int>( "system.file_history_size",
|
|
|
|
&m_System.file_history_size, 9 ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "system.language",
|
2023-01-22 14:41:33 +00:00
|
|
|
&m_System.language, wxS( "Default" ) ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "system.pdf_viewer_name",
|
2023-01-22 14:41:33 +00:00
|
|
|
&m_System.pdf_viewer_name, wxS( "" ) ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "system.use_system_pdf_viewer",
|
|
|
|
&m_System.use_system_pdf_viewer, true ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "system.working_dir",
|
2023-01-22 14:41:33 +00:00
|
|
|
&m_System.working_dir, wxS( "" ) ) );
|
2020-08-09 10:41:45 +00:00
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<int>( "system.clear_3d_cache_interval",
|
|
|
|
&m_System.clear_3d_cache_interval, 30 ) );
|
|
|
|
|
2021-07-27 14:13:26 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "do_not_show_again.zone_fill_warning",
|
|
|
|
&m_DoNotShowAgain.zone_fill_warning, false ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "do_not_show_again.env_var_overwrite_warning",
|
|
|
|
&m_DoNotShowAgain.env_var_overwrite_warning, false ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "do_not_show_again.scaled_3d_models_warning",
|
|
|
|
&m_DoNotShowAgain.scaled_3d_models_warning, false ) );
|
|
|
|
|
2022-04-02 01:21:55 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "do_not_show_again.data_collection_prompt",
|
|
|
|
&m_DoNotShowAgain.data_collection_prompt, false ) );
|
|
|
|
|
2023-11-23 01:03:34 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "do_not_show_again.update_check_prompt",
|
|
|
|
&m_DoNotShowAgain.update_check_prompt, false ) );
|
|
|
|
|
2020-08-24 02:01:14 +00:00
|
|
|
m_params.emplace_back( new PARAM<bool>( "session.remember_open_files",
|
2021-02-23 14:34:18 +00:00
|
|
|
&m_Session.remember_open_files, false ) );
|
|
|
|
|
2022-07-22 08:26:49 +00:00
|
|
|
m_params.emplace_back( new PARAM_LIST<wxString>( "session.pinned_symbol_libs",
|
|
|
|
&m_Session.pinned_symbol_libs, {} ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM_LIST<wxString>( "session.pinned_fp_libs",
|
|
|
|
&m_Session.pinned_fp_libs, {} ) );
|
|
|
|
|
2021-02-23 14:34:18 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "netclass_panel.sash_pos",
|
|
|
|
&m_NetclassPanel.sash_pos, 160 ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-11-14 13:10:24 +00:00
|
|
|
m_params.emplace_back( new PARAM<int>( "package_manager.sash_pos",
|
|
|
|
&m_PackageManager.sash_pos, 380 ) );
|
|
|
|
|
2023-09-14 21:39:42 +00:00
|
|
|
m_params.emplace_back( new PARAM_LAMBDA<nlohmann::json>( "git.repositories",
|
|
|
|
[&]() -> nlohmann::json
|
|
|
|
{
|
|
|
|
nlohmann::json ret = {};
|
|
|
|
|
|
|
|
for( const GIT_REPOSITORY& repo : m_Git.repositories )
|
|
|
|
{
|
|
|
|
nlohmann::json repoJson = {};
|
|
|
|
|
|
|
|
repoJson["name"] = repo.name;
|
|
|
|
repoJson["path"] = repo.path;
|
|
|
|
repoJson["authType"] = repo.authType;
|
|
|
|
repoJson["username"] = repo.username;
|
|
|
|
repoJson["ssh_path"] = repo.ssh_path;
|
|
|
|
repoJson["active"] = repo.active;
|
|
|
|
|
|
|
|
ret.push_back( repoJson );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
[&]( const nlohmann::json& aJson )
|
|
|
|
{
|
|
|
|
if( !aJson.is_array() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_Git.repositories.clear();
|
|
|
|
|
|
|
|
for( const auto& repoJson : aJson )
|
|
|
|
{
|
|
|
|
GIT_REPOSITORY repo;
|
|
|
|
|
|
|
|
repo.name = repoJson["name"].get<wxString>();
|
|
|
|
repo.path = repoJson["path"].get<wxString>();
|
|
|
|
repo.authType = repoJson["authType"].get<wxString>();
|
|
|
|
repo.username = repoJson["username"].get<wxString>();
|
|
|
|
repo.ssh_path = repoJson["ssh_path"].get<wxString>();
|
|
|
|
repo.active = repoJson["active"].get<bool>();
|
2023-10-21 15:31:55 +00:00
|
|
|
repo.checkValid = true;
|
2023-09-14 21:39:42 +00:00
|
|
|
|
|
|
|
m_Git.repositories.push_back( repo );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{} ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "git.authorName",
|
|
|
|
&m_Git.authorName, wxS( "" ) ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<wxString>( "git.authorEmail",
|
|
|
|
&m_Git.authorEmail, wxS( "" ) ) );
|
|
|
|
|
|
|
|
m_params.emplace_back( new PARAM<bool>( "git.useDefaultAuthor",
|
|
|
|
&m_Git.useDefaultAuthor, true ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-06 03:21:57 +00:00
|
|
|
registerMigration( 0, 1, std::bind( &COMMON_SETTINGS::migrateSchema0to1, this ) );
|
2021-01-11 11:48:51 +00:00
|
|
|
registerMigration( 1, 2, std::bind( &COMMON_SETTINGS::migrateSchema1to2, this ) );
|
2022-09-26 01:08:51 +00:00
|
|
|
registerMigration( 2, 3, std::bind( &COMMON_SETTINGS::migrateSchema2to3, this ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool COMMON_SETTINGS::migrateSchema0to1()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Schema version 0 to 1:
|
|
|
|
*
|
|
|
|
* mousewheel_pan is replaced by explicit settings for scroll wheel behavior
|
|
|
|
*/
|
|
|
|
|
|
|
|
nlohmann::json::json_pointer mwp_pointer( "/input/mousewheel_pan"_json_pointer );
|
|
|
|
|
|
|
|
bool mwp = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-06-04 03:52:50 +00:00
|
|
|
mwp = m_internals->at( mwp_pointer );
|
|
|
|
m_internals->At( "input" ).erase( "mousewheel_pan" );
|
2020-05-17 00:19:48 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
2022-02-03 20:57:26 +00:00
|
|
|
wxLogTrace( traceSettings, wxT( "COMMON_SETTINGS::Migrate 0->1: mousewheel_pan not found" ) );
|
2020-05-17 00:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( mwp )
|
|
|
|
{
|
2021-06-04 03:52:50 +00:00
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/horizontal_pan" )] = true;
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-06-04 03:52:50 +00:00
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_h" )] = WXK_SHIFT;
|
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_v" )] = 0;
|
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/scroll_modifier_zoom" )] = WXK_CONTROL;
|
2020-05-17 00:19:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-04 03:52:50 +00:00
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/horizontal_pan" )] = false;
|
2020-05-17 00:19:48 +00:00
|
|
|
|
2021-06-04 03:52:50 +00:00
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_h" )] = WXK_CONTROL;
|
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/scroll_modifier_pan_v" )] = WXK_SHIFT;
|
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/scroll_modifier_zoom" )] = 0;
|
2020-05-17 00:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-11 11:48:51 +00:00
|
|
|
bool COMMON_SETTINGS::migrateSchema1to2()
|
|
|
|
{
|
|
|
|
nlohmann::json::json_pointer v1_pointer( "/input/prefer_select_to_drag"_json_pointer );
|
|
|
|
|
|
|
|
bool prefer_selection = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-06-04 03:52:50 +00:00
|
|
|
prefer_selection = m_internals->at( v1_pointer );
|
|
|
|
m_internals->at( nlohmann::json::json_pointer( "/input"_json_pointer ) ).erase( "prefer_select_to_drag" );
|
2021-01-11 11:48:51 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
2022-02-03 20:57:26 +00:00
|
|
|
wxLogTrace( traceSettings, wxT( "COMMON_SETTINGS::Migrate 1->2: prefer_select_to_drag not found" ) );
|
2021-01-11 11:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( prefer_selection )
|
2021-06-04 03:52:50 +00:00
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/mouse_left" )] = MOUSE_DRAG_ACTION::SELECT;
|
2021-01-11 11:48:51 +00:00
|
|
|
else
|
2021-06-04 03:52:50 +00:00
|
|
|
( *m_internals )[nlohmann::json::json_pointer( "/input/mouse_left" )] = MOUSE_DRAG_ACTION::DRAG_ANY;
|
2021-01-11 11:48:51 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-26 01:08:51 +00:00
|
|
|
bool COMMON_SETTINGS::migrateSchema2to3()
|
|
|
|
{
|
|
|
|
wxFileName cfgpath;
|
2023-09-23 23:53:22 +00:00
|
|
|
cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
|
2022-09-26 01:08:51 +00:00
|
|
|
cfgpath.AppendDir( wxT( "3d" ) );
|
2023-01-22 14:41:33 +00:00
|
|
|
cfgpath.SetFullName( wxS( "3Dresolver.cfg" ) );
|
2022-09-26 01:08:51 +00:00
|
|
|
cfgpath.MakeAbsolute();
|
|
|
|
|
|
|
|
std::vector<LEGACY_3D_SEARCH_PATH> legacyPaths;
|
|
|
|
readLegacy3DResolverCfg( cfgpath.GetFullPath(), legacyPaths );
|
|
|
|
|
2022-11-10 11:19:55 +00:00
|
|
|
// env variables have a limited allowed character set for names
|
2023-01-22 14:41:33 +00:00
|
|
|
wxRegEx nonValidCharsRegex( wxS( "[^A-Z0-9_]+" ), wxRE_ADVANCED );
|
2022-11-10 11:19:55 +00:00
|
|
|
|
2022-09-26 01:08:51 +00:00
|
|
|
for( const LEGACY_3D_SEARCH_PATH& path : legacyPaths )
|
|
|
|
{
|
2022-11-10 11:19:55 +00:00
|
|
|
wxString key = path.m_Alias;
|
2022-09-26 01:08:51 +00:00
|
|
|
const wxString& val = path.m_Pathvar;
|
|
|
|
|
2022-11-10 11:19:55 +00:00
|
|
|
// The 3d alias config didnt use the same naming restrictions as real env variables
|
|
|
|
// We need to sanitize them
|
|
|
|
|
|
|
|
// upper case only
|
|
|
|
key.MakeUpper();
|
|
|
|
// logically swap - with _
|
|
|
|
key.Replace( wxS( "-" ), wxS( "_" ) );
|
|
|
|
|
|
|
|
// remove any other chars
|
|
|
|
nonValidCharsRegex.Replace( &key, wxEmptyString );
|
|
|
|
|
2022-09-26 01:08:51 +00:00
|
|
|
if( !m_Env.vars.count( key ) )
|
|
|
|
{
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceEnvVars, wxS( "COMMON_SETTINGS: Loaded new var: %s = %s" ), key, val );
|
2022-09-26 01:08:51 +00:00
|
|
|
m_Env.vars[key] = ENV_VAR_ITEM( key, val );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cfgpath.FileExists() )
|
|
|
|
{
|
|
|
|
wxRemoveFile( cfgpath.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
bool COMMON_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg )
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
ret &= fromLegacy<double>( aCfg, "CanvasScale", "appearance.canvas_scale" );
|
|
|
|
ret &= fromLegacy<int>( aCfg, "IconScale", "appearance.icon_scale" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "UseIconsInMenus", "appearance.use_icons_in_menus" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "ShowEnvVarWarningDialog", "environment.show_warning_dialog" );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
auto load_env_vars =
|
|
|
|
[&]()
|
|
|
|
{
|
|
|
|
wxString key, value;
|
|
|
|
long index = 0;
|
|
|
|
nlohmann::json::json_pointer ptr = m_internals->PointerFromString( "environment.vars" );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
aCfg->SetPath( "EnvironmentVariables" );
|
|
|
|
( *m_internals )[ptr] = nlohmann::json( {} );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
while( aCfg->GetNextEntry( key, index ) )
|
|
|
|
{
|
2024-01-16 22:20:45 +00:00
|
|
|
if( versionedEnvVarRegex.Matches( key ) )
|
2021-09-16 22:45:28 +00:00
|
|
|
{
|
2023-12-19 19:29:17 +00:00
|
|
|
wxLogTrace( traceSettings,
|
|
|
|
wxT( "Migrate Env: %s is blacklisted; skipping." ), key );
|
2021-09-16 22:45:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-02 15:47:06 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
value = aCfg->Read( key, wxEmptyString );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
if( !value.IsEmpty() )
|
|
|
|
{
|
|
|
|
ptr.push_back( key.ToStdString() );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2023-12-19 19:29:17 +00:00
|
|
|
wxLogTrace( traceSettings, wxT( "Migrate Env: %s=%s" ),
|
|
|
|
ptr.to_string(), value );
|
2021-09-16 22:45:28 +00:00
|
|
|
( *m_internals )[ptr] = value.ToUTF8();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
ptr.pop_back();
|
|
|
|
}
|
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2021-09-16 22:45:28 +00:00
|
|
|
aCfg->SetPath( ".." );
|
|
|
|
};
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
load_env_vars();
|
|
|
|
|
2020-05-27 01:37:57 +00:00
|
|
|
bool mousewheel_pan = false;
|
|
|
|
|
|
|
|
if( aCfg->Read( "MousewheelPAN", &mousewheel_pan ) && mousewheel_pan )
|
|
|
|
{
|
2021-06-04 03:52:50 +00:00
|
|
|
Set( "input.horizontal_pan", true );
|
|
|
|
Set( "input.scroll_modifier_pan_h", static_cast<int>( WXK_SHIFT ) );
|
|
|
|
Set( "input.scroll_modifier_pan_v", 0 );
|
|
|
|
Set( "input.scroll_modifier_zoom", static_cast<int>( WXK_CONTROL ) );
|
2020-05-27 01:37:57 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
ret &= fromLegacy<bool>( aCfg, "AutoPAN", "input.auto_pan" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "ImmediateActions", "input.immediate_actions" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "PreferSelectionToDragging", "input.prefer_select_to_drag" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "MoveWarpsCursor", "input.warp_mouse_on_move" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "ZoomNoCenter", "input.center_on_zoom" );
|
|
|
|
|
|
|
|
// This was stored inverted in legacy config
|
2022-08-25 22:50:47 +00:00
|
|
|
if( std::optional<bool> value = Get<bool>( "input.center_on_zoom" ) )
|
2021-06-04 03:52:50 +00:00
|
|
|
Set( "input.center_on_zoom", !( *value ) );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
ret &= fromLegacy<int>( aCfg, "OpenGLAntialiasingMode", "graphics.opengl_antialiasing_mode" );
|
|
|
|
ret &= fromLegacy<int>( aCfg, "CairoAntialiasingMode", "graphics.cairo_antialiasing_mode" );
|
|
|
|
|
|
|
|
ret &= fromLegacy<int>( aCfg, "AutoSaveInterval", "system.autosave_interval" );
|
|
|
|
ret &= fromLegacyString( aCfg, "Editor", "system.editor_name" );
|
|
|
|
ret &= fromLegacy<int>( aCfg, "FileHistorySize", "system.file_history_size" );
|
|
|
|
ret &= fromLegacyString( aCfg, "LanguageID", "system.language" );
|
|
|
|
ret &= fromLegacyString( aCfg, "PdfBrowserName", "system.pdf_viewer_name" );
|
|
|
|
ret &= fromLegacy<bool>( aCfg, "UseSystemBrowser", "system.use_system_pdf_viewer" );
|
|
|
|
ret &= fromLegacyString( aCfg, "WorkingDir", "system.working_dir" );
|
|
|
|
|
|
|
|
return ret;
|
2020-06-12 17:38:37 +00:00
|
|
|
}
|
2021-05-01 17:39:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
void COMMON_SETTINGS::InitializeEnvironment()
|
|
|
|
{
|
|
|
|
auto addVar =
|
|
|
|
[&]( const wxString& aKey, const wxString& aDefault )
|
|
|
|
{
|
|
|
|
m_Env.vars[aKey] = ENV_VAR_ITEM( aKey, aDefault, aDefault );
|
|
|
|
|
|
|
|
wxString envValue;
|
|
|
|
|
|
|
|
if( wxGetEnv( aKey, &envValue ) == true && !envValue.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_Env.vars[aKey].SetValue( envValue );
|
|
|
|
m_Env.vars[aKey].SetDefinedExternally();
|
|
|
|
wxLogTrace( traceEnvVars,
|
2023-01-22 14:41:33 +00:00
|
|
|
wxS( "InitializeEnvironment: Entry %s defined externally as %s" ), aKey,
|
2021-05-01 17:39:35 +00:00
|
|
|
envValue );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-19 19:29:17 +00:00
|
|
|
wxLogTrace( traceEnvVars, wxS( "InitializeEnvironment: Setting entry %s to "
|
|
|
|
"default %s" ),
|
2021-05-01 17:39:35 +00:00
|
|
|
aKey, aDefault );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wxFileName basePath( PATHS::GetStockEDALibraryPath(), wxEmptyString );
|
|
|
|
|
|
|
|
wxFileName path( basePath );
|
2021-03-21 14:05:40 +00:00
|
|
|
path.AppendDir( wxT( "footprints" ) );
|
2024-01-16 22:20:45 +00:00
|
|
|
addVar( ENV_VAR::GetVersionedEnvVarName( wxS( "FOOTPRINT_DIR" ) ), path.GetFullPath() );
|
2021-05-01 17:39:35 +00:00
|
|
|
|
|
|
|
path = basePath;
|
|
|
|
path.AppendDir( wxT( "3dmodels" ) );
|
2024-01-16 22:20:45 +00:00
|
|
|
addVar( ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ), path.GetFullPath() );
|
2021-05-01 17:39:35 +00:00
|
|
|
|
2024-01-16 22:20:45 +00:00
|
|
|
addVar( ENV_VAR::GetVersionedEnvVarName( wxS( "TEMPLATE_DIR" ) ),
|
|
|
|
PATHS::GetStockTemplatesPath() );
|
2021-05-01 17:39:35 +00:00
|
|
|
|
|
|
|
addVar( wxT( "KICAD_USER_TEMPLATE_DIR" ), PATHS::GetUserTemplatesPath() );
|
|
|
|
|
2024-01-16 22:20:45 +00:00
|
|
|
addVar( ENV_VAR::GetVersionedEnvVarName( wxS( "3RD_PARTY" ) ),
|
|
|
|
PATHS::GetDefault3rdPartyPath() );
|
2020-12-08 18:39:45 +00:00
|
|
|
|
2021-05-01 17:39:35 +00:00
|
|
|
path = basePath;
|
2021-03-21 14:05:40 +00:00
|
|
|
path.AppendDir( wxT( "symbols" ) );
|
2024-01-16 22:20:45 +00:00
|
|
|
addVar( ENV_VAR::GetVersionedEnvVarName( wxS( "SYMBOL_DIR" ) ), path.GetFullPath() );
|
2021-05-01 17:39:35 +00:00
|
|
|
}
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool COMMON_SETTINGS::readLegacy3DResolverCfg( const wxString& path,
|
|
|
|
std::vector<LEGACY_3D_SEARCH_PATH>& aSearchPaths )
|
|
|
|
{
|
|
|
|
wxFileName cfgpath( path );
|
|
|
|
|
|
|
|
// This should be the same as wxWidgets 3.0 wxPATH_NORM_ALL which is deprecated in 3.1.
|
|
|
|
// There are known issues with environment variable expansion so maybe we should be using
|
|
|
|
// our own ExpandEnvVarSubstitutions() here instead.
|
|
|
|
cfgpath.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
|
|
|
|
wxString cfgname = cfgpath.GetFullPath();
|
|
|
|
|
|
|
|
std::ifstream cfgFile;
|
|
|
|
std::string cfgLine;
|
|
|
|
|
|
|
|
if( !wxFileName::Exists( cfgname ) )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
wxString errmsg = "no 3D configuration file";
|
|
|
|
ostr << " * " << errmsg.ToUTF8() << " '";
|
|
|
|
ostr << cfgname.ToUTF8() << "'";
|
|
|
|
wxLogTrace( traceSettings, "%s\n", ostr.str().c_str() );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgFile.open( cfgname.ToUTF8() );
|
|
|
|
|
|
|
|
if( !cfgFile.is_open() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "Could not open configuration file" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << " '" << cfgname.ToUTF8() << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lineno = 0;
|
|
|
|
LEGACY_3D_SEARCH_PATH al;
|
|
|
|
size_t idx;
|
|
|
|
int vnum = 0; // version number
|
|
|
|
|
|
|
|
while( cfgFile.good() )
|
|
|
|
{
|
|
|
|
cfgLine.clear();
|
|
|
|
std::getline( cfgFile, cfgLine );
|
|
|
|
++lineno;
|
|
|
|
|
|
|
|
if( cfgLine.empty() )
|
|
|
|
{
|
|
|
|
if( cfgFile.eof() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 1 == lineno && cfgLine.compare( 0, 2, "#V" ) == 0 )
|
|
|
|
{
|
|
|
|
// extract the version number and parse accordingly
|
|
|
|
if( cfgLine.size() > 2 )
|
|
|
|
{
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( cfgLine.substr( 2 ) );
|
|
|
|
istr >> vnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
|
|
|
|
if( !getLegacy3DHollerith( cfgLine, idx, al.m_Alias ) )
|
|
|
|
continue;
|
|
|
|
|
2024-01-16 22:20:45 +00:00
|
|
|
// Don't add KICADn_3DMODEL_DIR, one of its legacy equivalents, or KIPRJMOD from a
|
|
|
|
// config file. They're system variables which are defined at runtime.
|
|
|
|
wxString versionedPath = wxString::Format( wxS( "${%s}" ),
|
|
|
|
ENV_VAR::GetVersionedEnvVarName( wxS( "3DMODEL_DIR" ) ) );
|
|
|
|
|
|
|
|
if( al.m_Alias == versionedPath || al.m_Alias == wxS( "${KIPRJMOD}" )
|
2023-01-22 14:41:33 +00:00
|
|
|
|| al.m_Alias == wxS( "$(KIPRJMOD)" ) || al.m_Alias == wxS( "${KISYS3DMOD}" )
|
|
|
|
|| al.m_Alias == wxS( "$(KISYS3DMOD)" ) )
|
2022-09-26 01:08:51 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !getLegacy3DHollerith( cfgLine, idx, al.m_Pathvar ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !getLegacy3DHollerith( cfgLine, idx, al.m_Description ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
aSearchPaths.push_back( al );
|
|
|
|
}
|
|
|
|
|
|
|
|
cfgFile.close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool COMMON_SETTINGS::getLegacy3DHollerith( const std::string& aString, size_t& aIndex,
|
|
|
|
wxString& aResult )
|
|
|
|
{
|
|
|
|
aResult.clear();
|
|
|
|
|
|
|
|
if( aIndex >= aString.size() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "bad Hollerith string on line" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t i2 = aString.find( '"', aIndex );
|
|
|
|
|
|
|
|
if( std::string::npos == i2 )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "missing opening quote mark in config file" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i2;
|
|
|
|
|
|
|
|
if( i2 >= aString.size() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "invalid entry (unexpected end of line)" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string tnum;
|
|
|
|
|
|
|
|
while( aString[i2] >= '0' && aString[i2] <= '9' )
|
|
|
|
tnum.append( 1, aString[i2++] );
|
|
|
|
|
|
|
|
if( tnum.empty() || aString[i2++] != ':' )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "bad Hollerith string on line" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::istringstream istr;
|
|
|
|
istr.str( tnum );
|
|
|
|
size_t nchars;
|
|
|
|
istr >> nchars;
|
|
|
|
|
|
|
|
if( ( i2 + nchars ) >= aString.size() )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "invalid entry (unexpected end of line)" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nchars > 0 )
|
|
|
|
{
|
|
|
|
aResult = wxString::FromUTF8( aString.substr( i2, nchars ).c_str() );
|
|
|
|
i2 += nchars;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( i2 >= aString.size() || aString[i2] != '"' )
|
|
|
|
{
|
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxString errmsg = wxS( "missing closing quote mark in config file" );
|
2022-09-26 01:08:51 +00:00
|
|
|
ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
|
2023-01-22 14:41:33 +00:00
|
|
|
wxLogTrace( traceSettings, wxS( "%s\n" ), ostr.str().c_str() );
|
2022-09-26 01:08:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aIndex = i2 + 1;
|
|
|
|
return true;
|
2022-10-19 23:25:45 +00:00
|
|
|
}
|