11using Windows . Storage ;
22using Windows . UI . Xaml . Controls ;
3-
3+ using System ;
4+ using Windows . UI . Xaml . Media ;
5+ using Windows . UI ;
6+ using System . IO ;
47
58namespace Files . SettingsPages
69{
@@ -28,6 +31,40 @@ public Preferences()
2831 AutoRefreshSwitch . IsOn = false ;
2932 }
3033
34+ if ( localSettings . Values [ "customLocationsSetting" ] != null )
35+ {
36+ if ( localSettings . Values [ "customLocationsSetting" ] . Equals ( true ) )
37+ {
38+ CustomLocationToggle . IsOn = true ;
39+ DownloadsL . IsEnabled = true ;
40+ DocumentsL . IsEnabled = true ;
41+ PictureL . IsEnabled = true ;
42+ MusicL . IsEnabled = true ;
43+ VideosL . IsEnabled = true ;
44+ SaveCustomL . IsEnabled = true ;
45+ }
46+ else
47+ {
48+ CustomLocationToggle . IsOn = false ;
49+ DownloadsL . IsEnabled = false ;
50+ DocumentsL . IsEnabled = false ;
51+ PictureL . IsEnabled = false ;
52+ MusicL . IsEnabled = false ;
53+ VideosL . IsEnabled = false ;
54+ SaveCustomL . IsEnabled = false ;
55+ }
56+ }
57+ else
58+ {
59+ CustomLocationToggle . IsOn = false ;
60+ DownloadsL . IsEnabled = false ;
61+ DocumentsL . IsEnabled = false ;
62+ PictureL . IsEnabled = false ;
63+ MusicL . IsEnabled = false ;
64+ VideosL . IsEnabled = false ;
65+ SaveCustomL . IsEnabled = false ;
66+ }
67+ SuccessMark . Visibility = Windows . UI . Xaml . Visibility . Collapsed ;
3168 }
3269
3370 private void AutoRefreshSwitch_Toggled ( object sender , Windows . UI . Xaml . RoutedEventArgs e )
@@ -42,5 +79,145 @@ private void AutoRefreshSwitch_Toggled(object sender, Windows.UI.Xaml.RoutedEven
4279 localSettings . Values [ "autoRefreshEnabledSetting" ] = false ;
4380 }
4481 }
82+
83+ private void ToggleSwitch_Toggled ( object sender , Windows . UI . Xaml . RoutedEventArgs e )
84+ {
85+ if ( ( sender as ToggleSwitch ) . IsOn )
86+ {
87+ localSettings . Values [ "customLocationsSetting" ] = true ;
88+ DownloadsL . IsEnabled = true ;
89+ DocumentsL . IsEnabled = true ;
90+ PictureL . IsEnabled = true ;
91+ MusicL . IsEnabled = true ;
92+ VideosL . IsEnabled = true ;
93+ SaveCustomL . IsEnabled = true ;
94+ }
95+ else
96+ {
97+ localSettings . Values [ "customLocationsSetting" ] = false ;
98+ DownloadsL . IsEnabled = false ;
99+ DocumentsL . IsEnabled = false ;
100+ PictureL . IsEnabled = false ;
101+ MusicL . IsEnabled = false ;
102+ VideosL . IsEnabled = false ;
103+ SaveCustomL . IsEnabled = false ;
104+ }
105+ }
106+
107+ private async void SaveCustomL_Click ( object sender , Windows . UI . Xaml . RoutedEventArgs e )
108+ {
109+ StorageFolder newLocationSetting ;
110+ if ( DownloadsL . Text != null )
111+ {
112+ try
113+ {
114+ newLocationSetting = await StorageFolder . GetFolderFromPathAsync ( DownloadsL . Text ) ;
115+ localSettings . Values [ "DownloadsLocation" ] = DownloadsL . Text ;
116+ }
117+ catch ( UnauthorizedAccessException )
118+ {
119+ await MainPage . permissionBox . ShowAsync ( ) ;
120+ return ;
121+ }
122+ catch ( ArgumentException )
123+ {
124+ DownloadsL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
125+ }
126+ catch ( FileNotFoundException )
127+ {
128+ DownloadsL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
129+ }
130+ }
131+
132+ if ( DocumentsL . Text != null )
133+ {
134+ try
135+ {
136+ newLocationSetting = await StorageFolder . GetFolderFromPathAsync ( DocumentsL . Text ) ;
137+ localSettings . Values [ "DocumentsLocation" ] = DocumentsL . Text ;
138+ }
139+ catch ( UnauthorizedAccessException )
140+ {
141+ await MainPage . permissionBox . ShowAsync ( ) ;
142+ return ;
143+ }
144+ catch ( ArgumentException )
145+ {
146+ DocumentsL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
147+ }
148+ catch ( FileNotFoundException )
149+ {
150+ DocumentsL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
151+ }
152+ }
153+
154+ if ( PictureL . Text != null )
155+ {
156+ try
157+ {
158+ newLocationSetting = await StorageFolder . GetFolderFromPathAsync ( PictureL . Text ) ;
159+ localSettings . Values [ "PicturesLocation" ] = PictureL . Text ;
160+ }
161+ catch ( UnauthorizedAccessException )
162+ {
163+ await MainPage . permissionBox . ShowAsync ( ) ;
164+ return ;
165+ }
166+ catch ( ArgumentException )
167+ {
168+ PictureL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
169+ }
170+ catch ( FileNotFoundException )
171+ {
172+ PictureL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
173+ }
174+ }
175+
176+ if ( MusicL . Text != null )
177+ {
178+ try
179+ {
180+ newLocationSetting = await StorageFolder . GetFolderFromPathAsync ( MusicL . Text ) ;
181+ localSettings . Values [ "MusicLocation" ] = MusicL . Text ;
182+ }
183+ catch ( UnauthorizedAccessException )
184+ {
185+ await MainPage . permissionBox . ShowAsync ( ) ;
186+ return ;
187+ }
188+ catch ( ArgumentException )
189+ {
190+ MusicL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
191+ }
192+ catch ( FileNotFoundException )
193+ {
194+ MusicL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
195+ }
196+ }
197+
198+ if ( VideosL . Text != null )
199+ {
200+ try
201+ {
202+ newLocationSetting = await StorageFolder . GetFolderFromPathAsync ( VideosL . Text ) ;
203+ localSettings . Values [ "VideosLocation" ] = VideosL . Text ;
204+ }
205+ catch ( UnauthorizedAccessException )
206+ {
207+ await MainPage . permissionBox . ShowAsync ( ) ;
208+ return ;
209+ }
210+ catch ( ArgumentException )
211+ {
212+ VideosL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
213+ }
214+ catch ( FileNotFoundException )
215+ {
216+ VideosL . BorderBrush = new SolidColorBrush ( Color . FromArgb ( 255 , 255 , 0 , 0 ) ) ;
217+ }
218+ }
219+
220+ SuccessMark . Visibility = Windows . UI . Xaml . Visibility . Visible ;
221+ }
45222 }
46223}
0 commit comments