@@ -18,9 +18,15 @@ namespace ShadesTweaker
18
18
{
19
19
public partial class MainWindow : UiWindow
20
20
{
21
+ private const string ConfigFileName = "config.xml" ;
22
+ private string configFilePath ;
21
23
public MainWindow ( )
22
24
{
23
25
InitializeComponent ( ) ;
26
+ configFilePath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , ConfigFileName ) ;
27
+
28
+
29
+ LoadLanguagePreference ( ) ;
24
30
Loaded += ( sender , args ) =>
25
31
{
26
32
if ( IsWindows11OrHigher ( ) )
@@ -33,7 +39,50 @@ public MainWindow()
33
39
}
34
40
} ;
35
41
}
42
+ private void LoadLanguagePreference ( )
43
+ {
44
+ if ( File . Exists ( configFilePath ) )
45
+ {
46
+ XDocument doc = XDocument . Load ( configFilePath ) ;
47
+ XElement languageIndexElement = doc . Element ( "Config" ) ? . Element ( "LanguageIndex" ) ;
48
+ if ( int . TryParse ( languageIndexElement ? . Value , out int languageIndex ) )
49
+ {
50
+ comboBoxLanguage . SelectedIndex = languageIndex ;
51
+ ApplyLanguage ( languageIndex ) ;
52
+ }
53
+ }
54
+ }
36
55
56
+ private void SaveLanguagePreference ( int languageIndex )
57
+ {
58
+ if ( ! string . IsNullOrEmpty ( configFilePath ) )
59
+ {
60
+ XDocument doc = new XDocument ( new XElement ( "Config" , new XElement ( "LanguageIndex" , languageIndex ) ) ) ;
61
+ doc . Save ( configFilePath ) ;
62
+ }
63
+ }
64
+
65
+
66
+ private void ApplyLanguage ( int languageIndex )
67
+ {
68
+ ResourceDictionary resourceDictionary = new ResourceDictionary ( ) ;
69
+
70
+ string basePath = AppDomain . CurrentDomain . BaseDirectory ;
71
+ string [ ] languageFiles = { "StringResources.en.xaml" , "StringResources.tr.xaml" , "StringResources.de.xaml" , "StringResources.es.xaml" , "StringResources.zh-cy.xaml" , "StringResources.ua.xaml" } ;
72
+
73
+ if ( languageIndex >= 0 && languageIndex < languageFiles . Length )
74
+ {
75
+ resourceDictionary . Source = new Uri ( Path . Combine ( basePath , languageFiles [ languageIndex ] ) ) ;
76
+ this . Resources . MergedDictionaries . Add ( resourceDictionary ) ;
77
+ }
78
+ }
79
+
80
+ private void comboBoxLanguage_SelectionChanged ( object sender , SelectionChangedEventArgs e )
81
+ {
82
+ int selectedLanguageIndex = comboBoxLanguage . SelectedIndex ;
83
+ SaveLanguagePreference ( selectedLanguageIndex ) ;
84
+ ApplyLanguage ( selectedLanguageIndex ) ;
85
+ }
37
86
private bool IsWindows11OrHigher ( )
38
87
{
39
88
// Windows 11 version number: 10.0.22000
@@ -1063,16 +1112,6 @@ private void xboxGameBar_Unchecked(object sender, RoutedEventArgs e)
1063
1112
RegHelper . SetValue ( RegistryHive . LocalMachine , @"SOFTWARE\Policies\Microsoft\Windows\GameDVR" , "AllowGameDVR" , 1 , RegistryValueKind . DWord ) ;
1064
1113
}
1065
1114
1066
- // Password Reveal Button
1067
- private void passwordReveal_Checked ( object sender , RoutedEventArgs e )
1068
- {
1069
- RegHelper . SetValue ( RegistryHive . CurrentUser , @"SOFTWARE\Policies\Microsoft\Windows\CredUI" , "DisablePasswordReveal" , 1 , RegistryValueKind . DWord ) ;
1070
- }
1071
-
1072
- private void passwordReveal_Unchecked ( object sender , RoutedEventArgs e )
1073
- {
1074
- RegHelper . SetValue ( RegistryHive . CurrentUser , @"SOFTWARE\Policies\Microsoft\Windows\CredUI" , "DisablePasswordReveal" , 0 , RegistryValueKind . DWord ) ;
1075
- }
1076
1115
1077
1116
// Location Sensors
1078
1117
private void locationSensors_Checked ( object sender , RoutedEventArgs e )
@@ -1444,7 +1483,6 @@ private void DownloadedMapsManager_Unchecked(object sender, RoutedEventArgs e)
1444
1483
private void FileHistoryService_Checked ( object sender , RoutedEventArgs e )
1445
1484
{
1446
1485
RegHelper . SetValue ( RegistryHive . LocalMachine , @"SYSTEM\CurrentControlSet\Services\fhsvc" , "Start" , 4 , RegistryValueKind . DWord ) ;
1447
-
1448
1486
}
1449
1487
private void FileHistoryService_Unchecked ( object sender , RoutedEventArgs e )
1450
1488
{
@@ -1565,12 +1603,46 @@ private void PrintSpoolerService_Unchecked(object sender, RoutedEventArgs e)
1565
1603
// Security Center Service
1566
1604
private void SecurityCenterService_Checked ( object sender , RoutedEventArgs e )
1567
1605
{
1568
- RegHelper . SetValue ( RegistryHive . LocalMachine , @"SYSTEM\CurrentControlSet\Services\wscsvc" , "Start" , 4 , RegistryValueKind . DWord ) ;
1606
+ try
1607
+ {
1608
+ using ( RegistryKey key = Registry . LocalMachine . OpenSubKey ( @"SYSTEM\CurrentControlSet\Services\wscsvc" , true ) )
1609
+ {
1610
+ if ( key != null )
1611
+ {
1612
+ key . SetValue ( "Start" , 4 , RegistryValueKind . DWord ) ;
1613
+ }
1614
+ else
1615
+ {
1616
+ // Anahtar bulunamadı
1617
+ }
1618
+ }
1619
+ }
1620
+ catch ( Exception ex )
1621
+ {
1622
+ // Hata işleme
1623
+ }
1569
1624
}
1570
1625
1571
1626
private void SecurityCenterService_Unchecked ( object sender , RoutedEventArgs e )
1572
1627
{
1573
- RegHelper . SetValue ( RegistryHive . LocalMachine , @"SYSTEM\CurrentControlSet\Services\wscsvc" , "Start" , 2 , RegistryValueKind . DWord ) ;
1628
+ try
1629
+ {
1630
+ using ( RegistryKey key = Registry . LocalMachine . OpenSubKey ( @"SYSTEM\CurrentControlSet\Services\wscsvc" , true ) )
1631
+ {
1632
+ if ( key != null )
1633
+ {
1634
+ key . SetValue ( "Start" , 2 , RegistryValueKind . DWord ) ;
1635
+ }
1636
+ else
1637
+ {
1638
+ // Anahtar bulunamadı
1639
+ }
1640
+ }
1641
+ }
1642
+ catch ( Exception ex )
1643
+ {
1644
+ // Hata işleme
1645
+ }
1574
1646
}
1575
1647
1576
1648
// Windows Error Reporting Service
@@ -1933,7 +2005,7 @@ await Task.Run(() =>
1933
2005
{
1934
2006
if ( ! MessageBoxShown )
1935
2007
{
1936
- System . Windows . MessageBox . Show ( "Bazı dosyalar ve klasörler arkaplanda açık uygulamalar tarafından kullanılıyor, bu dosya ve klasörler silinemeyecek !." ) ;
2008
+ System . Windows . MessageBox . Show ( "Some files and folders are used in the background by open applications, these files and folders will not be deleted !." ) ;
1937
2009
MessageBoxShown = true ; // MessageBox gösterildiğini işaretle
1938
2010
}
1939
2011
}
@@ -1954,7 +2026,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
1954
2026
isProcessing = true ;
1955
2027
await Task . Delay ( 3000 ) ;
1956
2028
1957
- if ( LogsCheckbox . IsChecked == true )
2029
+ if ( logsCheckbox . IsChecked == true )
1958
2030
{
1959
2031
string updateLogsPath = @"C:\Windows\Logs\" ;
1960
2032
if ( Directory . Exists ( updateLogsPath ) )
@@ -1987,7 +2059,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
1987
2059
}
1988
2060
}
1989
2061
1990
- if ( WindowsOldCheckbox . IsChecked == true )
2062
+ if ( windowsOldCheckbox . IsChecked == true )
1991
2063
{
1992
2064
string windowsOldPath = @"C:\Windows.old\" ;
1993
2065
if ( Directory . Exists ( windowsOldPath ) )
@@ -2003,7 +2075,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
2003
2075
}
2004
2076
}
2005
2077
2006
- if ( erroreportingCheckbox . IsChecked == true )
2078
+ if ( errorReportingCheckbox . IsChecked == true )
2007
2079
{
2008
2080
string werPath = @"C:\ProgramData\Microsoft\Windows\WER\" ;
2009
2081
if ( Directory . Exists ( werPath ) )
@@ -2019,7 +2091,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
2019
2091
}
2020
2092
}
2021
2093
2022
- if ( programdatacachesCheckbox . IsChecked == true )
2094
+ if ( programDataCachesCheckbox . IsChecked == true )
2023
2095
{
2024
2096
string cachesPath = @"C:\ProgramData\Microsoft\Windows\Caches\" ;
2025
2097
if ( Directory . Exists ( cachesPath ) )
@@ -2052,7 +2124,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
2052
2124
}
2053
2125
}
2054
2126
2055
- if ( recyclebinCheckbox . IsChecked == true )
2127
+ if ( recycleBinCheckbox . IsChecked == true )
2056
2128
{
2057
2129
string cachesPath = @"C:\$Recycle.Bin" ;
2058
2130
if ( Directory . Exists ( cachesPath ) )
@@ -2068,7 +2140,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
2068
2140
}
2069
2141
}
2070
2142
2071
- if ( searchindexCheckbox . IsChecked == true )
2143
+ if ( searchIndexCheckbox . IsChecked == true )
2072
2144
{
2073
2145
string cachesPath = @"C:\ProgramData\Microsoft\Search\Data\" ;
2074
2146
if ( Directory . Exists ( cachesPath ) )
@@ -2100,7 +2172,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
2100
2172
}
2101
2173
}
2102
2174
2103
- if ( fontcacheCheckbox . IsChecked == true )
2175
+ if ( fontCacheCheckbox . IsChecked == true )
2104
2176
{
2105
2177
string cachesPath = @"C:\Windows\ServiceProfiles\LocalService\AppData\Local\FontCache" ;
2106
2178
if ( Directory . Exists ( cachesPath ) )
@@ -2116,7 +2188,7 @@ private async void AnalyzeButton_Click(object sender, RoutedEventArgs e)
2116
2188
}
2117
2189
}
2118
2190
2119
- if ( ınstallerCheckbox . IsChecked == true )
2191
+ if ( installerCheckbox . IsChecked == true )
2120
2192
{
2121
2193
string cachesPath = @"C:\Windows\Installer" ;
2122
2194
if ( Directory . Exists ( cachesPath ) )
@@ -2157,7 +2229,7 @@ private async void CleanButton_Click(object sender, RoutedEventArgs e)
2157
2229
2158
2230
/// CLEAR BAŞLANGICI ///
2159
2231
2160
- if ( LogsCheckbox . IsChecked == true )
2232
+ if ( logsCheckbox . IsChecked == true )
2161
2233
{
2162
2234
selectedPath [ 0 ] = @"C:\Windows\Logs\" ;
2163
2235
}
@@ -2168,17 +2240,17 @@ private async void CleanButton_Click(object sender, RoutedEventArgs e)
2168
2240
selectedPath [ 1 ] = Path . Combine ( @"C:\Users" , username , "AppData" , "Local" , "Temp" ) ;
2169
2241
}
2170
2242
2171
- if ( WindowsOldCheckbox . IsChecked == true )
2243
+ if ( windowsOldCheckbox . IsChecked == true )
2172
2244
{
2173
2245
selectedPath [ 2 ] = Path . Combine ( @"C:\Windows.old" ) ;
2174
2246
}
2175
2247
2176
- if ( erroreportingCheckbox . IsChecked == true )
2248
+ if ( errorReportingCheckbox . IsChecked == true )
2177
2249
{
2178
2250
selectedPath [ 3 ] = Path . Combine ( @"C:\ProgramData\Microsoft\Windows\WER" ) ;
2179
2251
}
2180
2252
2181
- if ( programdatacachesCheckbox . IsChecked == true )
2253
+ if ( programDataCachesCheckbox . IsChecked == true )
2182
2254
{
2183
2255
selectedPath [ 4 ] = Path . Combine ( @"C:\ProgramData\Microsoft\Windows\Caches" ) ;
2184
2256
}
@@ -2189,12 +2261,12 @@ private async void CleanButton_Click(object sender, RoutedEventArgs e)
2189
2261
selectedPath [ 5 ] = Path . Combine ( @"C:\Users" , username , "Downloads" ) ;
2190
2262
}
2191
2263
2192
- if ( recyclebinCheckbox . IsChecked == true )
2264
+ if ( recycleBinCheckbox . IsChecked == true )
2193
2265
{
2194
2266
selectedPath [ 6 ] = Path . Combine ( @"C:\$Recycle.Bin" ) ;
2195
2267
}
2196
2268
2197
- if ( searchindexCheckbox . IsChecked == true )
2269
+ if ( searchIndexCheckbox . IsChecked == true )
2198
2270
{
2199
2271
selectedPath [ 7 ] = Path . Combine ( @"C:\ProgramData\Microsoft\Search\Data" ) ;
2200
2272
}
@@ -2204,12 +2276,12 @@ private async void CleanButton_Click(object sender, RoutedEventArgs e)
2204
2276
selectedPath [ 8 ] = Path . Combine ( @"C:\Windows\Prefetch" ) ;
2205
2277
}
2206
2278
2207
- if ( fontcacheCheckbox . IsChecked == true )
2279
+ if ( fontCacheCheckbox . IsChecked == true )
2208
2280
{
2209
2281
selectedPath [ 9 ] = Path . Combine ( @"C:\Windows\ServiceProfiles\LocalService\AppData\Local\FontCache" ) ;
2210
2282
}
2211
2283
2212
- if ( ınstallerCheckbox . IsChecked == true )
2284
+ if ( installerCheckbox . IsChecked == true )
2213
2285
{
2214
2286
selectedPath [ 10 ] = Path . Combine ( @"C:\Windows\Installer" ) ;
2215
2287
}
@@ -2234,33 +2306,5 @@ private void TakeOwnership(string filePath)
2234
2306
}
2235
2307
}
2236
2308
2237
- private void comboBoxLanguage_SelectionChanged ( object sender , SelectionChangedEventArgs e )
2238
- {
2239
- ResourceDictionary resourceDictionary = new ResourceDictionary ( ) ;
2240
- string basePath = AppDomain . CurrentDomain . BaseDirectory ; // Programın çalıştığı dizin
2241
-
2242
- if ( comboBoxLanguage . SelectedIndex == 0 )
2243
- {
2244
- resourceDictionary . Source = new Uri ( Path . Combine ( basePath , "StringResources.en.xaml" ) ) ;
2245
- }
2246
- else if ( comboBoxLanguage . SelectedIndex == 1 )
2247
- {
2248
- resourceDictionary . Source = new Uri ( Path . Combine ( basePath , "StringResources.tr.xaml" ) ) ;
2249
- }
2250
- else if ( comboBoxLanguage . SelectedIndex == 2 )
2251
- {
2252
- resourceDictionary . Source = new Uri ( Path . Combine ( basePath , "StringResources.de.xaml" ) ) ;
2253
- }
2254
- else if ( comboBoxLanguage . SelectedIndex == 3 )
2255
- {
2256
- resourceDictionary . Source = new Uri ( Path . Combine ( basePath , "StringResources.es.xaml" ) ) ;
2257
- }
2258
- this . Resources . MergedDictionaries . Add ( resourceDictionary ) ;
2259
- }
2260
-
2261
-
2262
-
2263
-
2264
-
2265
2309
}
2266
2310
}
0 commit comments