@@ -45,11 +45,11 @@ public MainViewModel(
4545 Messenger . Default . Register < NotificationMessage > ( this , OnStatusMessage ) ;
4646
4747 // Set working directory
48- string appData = GetAppDataFolder ( ) ;
49- Directory . SetCurrentDirectory ( appData ) ;
48+ string userData = GetUserDataFolder ( ) ;
49+ Directory . SetCurrentDirectory ( userData ) ;
5050
5151 // Read configuration
52- ReadConfigAsync ( appData ) ;
52+ ReadConfigAsync ( userData ) ;
5353 }
5454
5555 public RelayCommand SaveCommand { get ; }
@@ -75,24 +75,33 @@ public string StatusMessage
7575
7676 public void SaveAll ( )
7777 {
78- string appData = GetAppDataFolder ( ) ;
78+ string appData = GetUserDataFolder ( ) ;
7979 SaveConfig ( appData ) ;
8080 }
8181
82- private void OnStatusMessage ( NotificationMessage message )
82+ public static string GetAppDataFolder ( )
8383 {
84- StatusMessage = message . Notification ;
85- if ( string . IsNullOrWhiteSpace ( message . Notification ) )
86- return ;
84+ string appData = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
85+ GetAssemblyInfo ( out string company , out string product ) ;
86+ string path = Path . Combine ( appData , company , product ) ;
87+ Directory . CreateDirectory ( path ) ;
88+ return path ;
8789 }
8890
89- private static string GetAppDataFolder ( )
91+ public static string GetUserDataFolder ( )
9092 {
91- string appData = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ;
93+ string userData = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) ;
94+ GetAssemblyInfo ( out string company , out string product ) ;
95+ string path = Path . Combine ( userData , company , product ) ;
96+ Directory . CreateDirectory ( path ) ;
97+ return path ;
98+ }
9299
100+ private static void GetAssemblyInfo ( out string company , out string product )
101+ {
93102 Assembly assembly = Assembly . GetEntryAssembly ( ) ;
94- string company = string . Empty ;
95- string product = string . Empty ;
103+ company = string . Empty ;
104+ product = string . Empty ;
96105 object [ ] companyAttributes = assembly . GetCustomAttributes ( typeof ( AssemblyCompanyAttribute ) , false ) ;
97106 if ( ( companyAttributes != null ) && ( companyAttributes . Length > 0 ) )
98107 {
@@ -104,19 +113,24 @@ private static string GetAppDataFolder()
104113 {
105114 product = ( ( AssemblyProductAttribute ) productAttributes [ 0 ] ) . Product ;
106115 }
116+ }
107117
108- string path = Path . Combine ( appData , company , product ) ;
109- Directory . CreateDirectory ( path ) ;
110- return path ;
118+ private void OnStatusMessage ( NotificationMessage message )
119+ {
120+ StatusMessage = message . Notification ;
121+ if ( string . IsNullOrWhiteSpace ( message . Notification ) )
122+ return ;
111123 }
112124
113125 private void ReadConfigAsync ( string appData )
114126 {
127+ string contentFolder = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Data" ) ;
115128 try
116129 {
117130 IsBusy = true ;
118- SettingsViewModel . Read ( Path . Combine ( appData , "Settings.json" ) ) ;
119- DevicesViewModel . Read ( Path . Combine ( appData , "Devices.json" ) ) ;
131+
132+ SettingsViewModel . Read ( Path . Combine ( appData , "Settings.json" ) , Path . Combine ( contentFolder , "Settings.json" ) ) ;
133+ DevicesViewModel . Read ( Path . Combine ( appData , "Devices.json" ) , Path . Combine ( contentFolder , "Devices.json" ) ) ;
120134 }
121135 finally
122136 {
0 commit comments