@@ -3,7 +3,7 @@ use std::path::PathBuf;
33use eframe:: Storage ;
44use globset:: Glob ;
55use objdiff_core:: {
6- config:: ScratchConfig ,
6+ config:: { ScratchConfig , SymbolMappings } ,
77 diff:: {
88 ArmArchVersion , ArmR9Usage , DiffObjConfig , FunctionRelocDiffs , MipsAbi , MipsInstrCategory ,
99 X86Formatter ,
@@ -18,15 +18,16 @@ pub struct AppConfigVersion {
1818}
1919
2020impl Default for AppConfigVersion {
21- fn default ( ) -> Self { Self { version : 2 } }
21+ fn default ( ) -> Self { Self { version : 3 } }
2222}
2323
2424/// Deserialize the AppConfig from storage, handling upgrades from older versions.
2525pub fn deserialize_config ( storage : & dyn Storage ) -> Option < AppConfig > {
2626 let str = storage. get_string ( CONFIG_KEY ) ?;
2727 match ron:: from_str :: < AppConfigVersion > ( & str) {
2828 Ok ( version) => match version. version {
29- 2 => from_str :: < AppConfig > ( & str) ,
29+ 3 => from_str :: < AppConfig > ( & str) ,
30+ 2 => from_str :: < AppConfigV2 > ( & str) . map ( |c| c. into_config ( ) ) ,
3031 1 => from_str :: < AppConfigV1 > ( & str) . map ( |c| c. into_config ( ) ) ,
3132 _ => {
3233 log:: warn!( "Unknown config version: {}" , version. version) ;
@@ -52,6 +53,119 @@ where T: serde::de::DeserializeOwned {
5253 }
5354}
5455
56+ #[ derive( serde:: Deserialize , serde:: Serialize ) ]
57+ pub struct ScratchConfigV2 {
58+ #[ serde( default ) ]
59+ pub platform : Option < String > ,
60+ #[ serde( default ) ]
61+ pub compiler : Option < String > ,
62+ #[ serde( default ) ]
63+ pub c_flags : Option < String > ,
64+ #[ serde( default ) ]
65+ pub ctx_path : Option < PathBuf > ,
66+ #[ serde( default ) ]
67+ pub build_ctx : Option < bool > ,
68+ #[ serde( default ) ]
69+ pub preset_id : Option < u32 > ,
70+ }
71+
72+ impl ScratchConfigV2 {
73+ fn into_config ( self ) -> ScratchConfig {
74+ ScratchConfig {
75+ platform : self . platform ,
76+ compiler : self . compiler ,
77+ c_flags : self . c_flags ,
78+ ctx_path : self . ctx_path ,
79+ build_ctx : self . build_ctx ,
80+ preset_id : self . preset_id ,
81+ }
82+ }
83+ }
84+
85+ #[ derive( serde:: Deserialize , serde:: Serialize ) ]
86+ pub struct ObjectConfigV2 {
87+ pub name : String ,
88+ pub target_path : Option < PathBuf > ,
89+ pub base_path : Option < PathBuf > ,
90+ pub reverse_fn_order : Option < bool > ,
91+ pub complete : Option < bool > ,
92+ pub scratch : Option < ScratchConfigV2 > ,
93+ pub source_path : Option < String > ,
94+ #[ serde( default ) ]
95+ pub symbol_mappings : SymbolMappings ,
96+ }
97+
98+ impl ObjectConfigV2 {
99+ fn into_config ( self ) -> ObjectConfig {
100+ ObjectConfig {
101+ name : self . name ,
102+ target_path : self . target_path ,
103+ base_path : self . base_path ,
104+ reverse_fn_order : self . reverse_fn_order ,
105+ complete : self . complete ,
106+ scratch : self . scratch . map ( |scratch| scratch. into_config ( ) ) ,
107+ source_path : self . source_path ,
108+ symbol_mappings : self . symbol_mappings ,
109+ }
110+ }
111+ }
112+
113+ #[ derive( serde:: Deserialize , serde:: Serialize ) ]
114+ pub struct AppConfigV2 {
115+ pub version : u32 ,
116+ #[ serde( default ) ]
117+ pub custom_make : Option < String > ,
118+ #[ serde( default ) ]
119+ pub custom_args : Option < Vec < String > > ,
120+ #[ serde( default ) ]
121+ pub selected_wsl_distro : Option < String > ,
122+ #[ serde( default ) ]
123+ pub project_dir : Option < PathBuf > ,
124+ #[ serde( default ) ]
125+ pub target_obj_dir : Option < PathBuf > ,
126+ #[ serde( default ) ]
127+ pub base_obj_dir : Option < PathBuf > ,
128+ #[ serde( default ) ]
129+ pub selected_obj : Option < ObjectConfigV2 > ,
130+ #[ serde( default = "bool_true" ) ]
131+ pub build_base : bool ,
132+ #[ serde( default ) ]
133+ pub build_target : bool ,
134+ #[ serde( default = "bool_true" ) ]
135+ pub rebuild_on_changes : bool ,
136+ #[ serde( default ) ]
137+ pub auto_update_check : bool ,
138+ #[ serde( default ) ]
139+ pub watch_patterns : Vec < Glob > ,
140+ #[ serde( default ) ]
141+ pub recent_projects : Vec < PathBuf > ,
142+ #[ serde( default ) ]
143+ pub diff_obj_config : DiffObjConfigV1 ,
144+ }
145+
146+ impl AppConfigV2 {
147+ fn into_config ( self ) -> AppConfig {
148+ log:: info!( "Upgrading configuration from v2" ) ;
149+ AppConfig {
150+ custom_make : self . custom_make ,
151+ custom_args : self . custom_args ,
152+ selected_wsl_distro : self . selected_wsl_distro ,
153+ project_dir : self . project_dir ,
154+ target_obj_dir : self . target_obj_dir ,
155+ base_obj_dir : self . base_obj_dir ,
156+ selected_obj : self . selected_obj . map ( |obj| obj. into_config ( ) ) ,
157+ build_base : self . build_base ,
158+ build_target : self . build_target ,
159+ rebuild_on_changes : self . rebuild_on_changes ,
160+ auto_update_check : self . auto_update_check ,
161+ watch_patterns : self . watch_patterns ,
162+ recent_projects : self . recent_projects ,
163+ diff_obj_config : self . diff_obj_config . into_config ( ) ,
164+ ..Default :: default ( )
165+ }
166+ }
167+ }
168+
55169#[ derive( serde:: Deserialize , serde:: Serialize ) ]
56170pub struct ScratchConfigV1 {
57171 #[ serde( default ) ]
0 commit comments