Skip to content

Commit a6d577b

Browse files
authored
Merge pull request #439 from IridiumIO/Refactor-Settings
Refactor settings menu
2 parents 5a8428a + 785c3b0 commit a6d577b

File tree

10 files changed

+349
-404
lines changed

10 files changed

+349
-404
lines changed

CompactGUI/Components/Settings/SettingsControl.xaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

CompactGUI/Components/Settings/SettingsControl.xaml.vb

Lines changed: 0 additions & 29 deletions
This file was deleted.

CompactGUI/Components/Settings/Settings_main.xaml

Lines changed: 0 additions & 154 deletions
This file was deleted.

CompactGUI/Components/Settings/Settings_main.xaml.vb

Lines changed: 0 additions & 130 deletions
This file was deleted.

CompactGUI/Models/Settings.vb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Imports Microsoft.Toolkit.Mvvm.ComponentModel
2+
3+
Public Class Settings : Inherits ObservableObject
4+
5+
Public Property SettingsVersion As Decimal = SettingsHandler.SettingsVersion
6+
Public Property ResultsDBLastUpdated As DateTime = DateTime.UnixEpoch
7+
Public Property SelectedCompressionMode As Integer = 0
8+
Public Property SkipNonCompressable As Boolean = False
9+
Public Property SkipUserNonCompressable As Boolean = False
10+
Public Property WatchFolderForChanges As Boolean = False
11+
Public Property NonCompressableList As New List(Of String) From {".dl_", ".gif", ".jpg", ".jpeg", ".png", ".wmf", ".mkv", ".mp4", ".wmv", ".avi", ".bik", ".bk2", ".flv", ".ogg", ".mpg", ".m2v", ".m4v", ".vob", ".mp3", ".aac", ".wma", ".flac", ".zip", ".xap", ".rar", ".7z", ".cab", ".lzx", ".docx", ".xlsx", ".pptx", ".vssx", ".vstx", ".onepkg", ".tar", ".gz", ".dmg", ".bz2", ".tgz", ".lz", ".xz", ".txz"}
12+
Public Property IsContextIntegrated As Boolean = False
13+
Public Property IsStartMenuEnabled As Boolean = False
14+
Public Property SkipUserFileTypesLevel As Integer = 0
15+
Public Property ShowNotifications As Boolean = False
16+
Public Property StartInSystemTray As Boolean = False
17+
18+
Private _EnableBackgroundWatcher As Boolean = True
19+
Public Property EnableBackgroundWatcher As Boolean
20+
Get
21+
Return _EnableBackgroundWatcher
22+
End Get
23+
Set(value As Boolean)
24+
_EnableBackgroundWatcher = value
25+
Watcher.Watcher.IsWatchingEnabled = value
26+
End Set
27+
End Property
28+
29+
Private _EnableBackgroundAutoCompression As Boolean = True
30+
Public Property EnableBackgroundAutoCompression As Boolean
31+
Get
32+
Return _EnableBackgroundAutoCompression
33+
End Get
34+
Set(value As Boolean)
35+
_EnableBackgroundAutoCompression = value
36+
Watcher.Watcher.IsBackgroundCompactingEnabled = value
37+
End Set
38+
End Property
39+
40+
Private _WindowScalingFactor = 1
41+
Public Property WindowScalingFactor As Double
42+
Get
43+
Return _WindowScalingFactor
44+
End Get
45+
Set(value As Double)
46+
_WindowScalingFactor = value
47+
WindowWidth = 500 * value
48+
WindowHeight = 800 * value
49+
50+
OnPropertyChanged()
51+
End Set
52+
End Property
53+
54+
Public Property WindowWidth As Decimal = 500
55+
Public Property WindowHeight As Decimal = 800
56+
57+
Public Property AllowMultiInstance As Boolean = False
58+
59+
'TODO: Add local saving of per-folder skip list
60+
Public Sub Save()
61+
SettingsHandler.WriteToFile()
62+
End Sub
63+
64+
End Class

CompactGUI/Models/SetttingsHandler.vb

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Imports System.Text.Json
2+
23
Imports Microsoft.Toolkit.Mvvm.ComponentModel
34

45
Public Class SettingsHandler : Inherits ObservableObject
@@ -81,67 +82,3 @@ Public Class SettingsHandler : Inherits ObservableObject
8182
End Sub
8283

8384
End Class
84-
85-
86-
Public Class Settings : Inherits ObservableObject
87-
88-
Public Property SettingsVersion As Decimal = SettingsHandler.SettingsVersion
89-
Public Property ResultsDBLastUpdated As DateTime = DateTime.UnixEpoch
90-
Public Property SelectedCompressionMode As Integer = 0
91-
Public Property SkipNonCompressable As Boolean = False
92-
Public Property SkipUserNonCompressable As Boolean = False
93-
Public Property WatchFolderForChanges As Boolean = False
94-
Public Property NonCompressableList As New List(Of String) From {".dl_", ".gif", ".jpg", ".jpeg", ".png", ".wmf", ".mkv", ".mp4", ".wmv", ".avi", ".bik", ".bk2", ".flv", ".ogg", ".mpg", ".m2v", ".m4v", ".vob", ".mp3", ".aac", ".wma", ".flac", ".zip", ".xap", ".rar", ".7z", ".cab", ".lzx", ".docx", ".xlsx", ".pptx", ".vssx", ".vstx", ".onepkg", ".tar", ".gz", ".dmg", ".bz2", ".tgz", ".lz", ".xz", ".txz"}
95-
Public Property IsContextIntegrated As Boolean = False
96-
Public Property IsStartMenuEnabled As Boolean = False
97-
Public Property SkipUserFileTypesLevel As Integer = 0
98-
Public Property ShowNotifications As Boolean = False
99-
Public Property StartInSystemTray As Boolean = False
100-
101-
Private _EnableBackgroundWatcher As Boolean = True
102-
Public Property EnableBackgroundWatcher As Boolean
103-
Get
104-
Return _EnableBackgroundWatcher
105-
End Get
106-
Set(value As Boolean)
107-
_EnableBackgroundWatcher = value
108-
Watcher.Watcher.IsWatchingEnabled = value
109-
End Set
110-
End Property
111-
112-
Private _EnableBackgroundAutoCompression As Boolean = True
113-
Public Property EnableBackgroundAutoCompression As Boolean
114-
Get
115-
Return _EnableBackgroundAutoCompression
116-
End Get
117-
Set(value As Boolean)
118-
_EnableBackgroundAutoCompression = value
119-
Watcher.Watcher.IsBackgroundCompactingEnabled = value
120-
End Set
121-
End Property
122-
123-
Private _WindowScalingFactor = 1
124-
Public Property WindowScalingFactor As Double
125-
Get
126-
Return _WindowScalingFactor
127-
End Get
128-
Set(value As Double)
129-
_WindowScalingFactor = value
130-
WindowWidth = 500 * value
131-
WindowHeight = 800 * value
132-
133-
OnPropertyChanged()
134-
End Set
135-
End Property
136-
137-
Public Property WindowWidth As Decimal = 500
138-
Public Property WindowHeight As Decimal = 800
139-
140-
Public Property AllowMultiInstance As Boolean = False
141-
142-
'TODO: Add local saving of per-folder skip list
143-
Public Sub Save()
144-
SettingsHandler.WriteToFile()
145-
End Sub
146-
147-
End Class
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Imports Microsoft.Toolkit.Mvvm.ComponentModel
2+
Imports Microsoft.Toolkit.Mvvm.Input
3+
Imports Microsoft.Win32
4+
5+
Public Class SettingsViewModel : Inherits ObservableObject
6+
7+
8+
Public Property AppSettings As Settings = SettingsHandler.AppSettings
9+
10+
Public Sub New()
11+
AddExecutableToRegistry()
12+
AddHandler AppSettings.PropertyChanged, AddressOf SettingsPropertyChanged
13+
SetEnv()
14+
End Sub
15+
16+
17+
Private Async Sub SetEnv()
18+
Await Task.Run(Sub() Environment.SetEnvironmentVariable("IridiumIO", IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "IridiumIO"), EnvironmentVariableTarget.User))
19+
End Sub
20+
21+
Private Sub SettingsPropertyChanged()
22+
SettingsHandler.AppSettings.Save()
23+
End Sub
24+
25+
26+
Sub AddExecutableToRegistry()
27+
Registry.SetValue("HKEY_CURRENT_USER\software\IridiumIO\CompactGUI\", "Executable Path", IO.Directory.GetCurrentDirectory)
28+
End Sub
29+
30+
Private Sub AddToContextMenu()
31+
32+
Registry.SetValue("HKEY_CURRENT_USER\Software\Classes\Directory\shell\CompactGUI", "", "Compress Folder")
33+
Registry.SetValue("HKEY_CURRENT_USER\Software\Classes\Directory\shell\CompactGUI", "Icon", Environment.ProcessPath)
34+
Registry.SetValue("HKEY_CURRENT_USER\Software\Classes\Directory\shell\CompactGUI\command", "", Environment.ProcessPath + " " + """%1""")
35+
36+
SettingsHandler.AppSettings.IsContextIntegrated = True
37+
SettingsHandler.AppSettings.Save()
38+
39+
End Sub
40+
41+
42+
Private Sub RemoveFromContextMenu()
43+
Microsoft.Win32.Registry.CurrentUser.DeleteSubKey("Software\\Classes\\Directory\\shell\\CompactGUI\command")
44+
45+
Microsoft.Win32.Registry.CurrentUser.DeleteSubKey("Software\\Classes\\Directory\\shell\\CompactGUI")
46+
47+
SettingsHandler.AppSettings.IsContextIntegrated = False
48+
SettingsHandler.AppSettings.Save()
49+
End Sub
50+
51+
52+
Public Property EditSkipListCommand As ICommand = New RelayCommand(Sub()
53+
Dim fl As New Settings_skiplistflyout
54+
fl.ShowDialog()
55+
End Sub)
56+
57+
Public Property AddToContextMenuCommand As ICommand = New RelayCommand(AddressOf AddToContextMenu)
58+
Public Property RemoveFromContextMenuCommand As ICommand = New RelayCommand(AddressOf RemoveFromContextMenu)
59+
Public Property UIScalingSliderCommand As ICommand = New RelayCommand(Of Double)(Sub(val) SettingsHandler.AppSettings.WindowScalingFactor = val)
60+
Public Property DisableAutoCompressionCommand As ICommand = New RelayCommand(Sub() AppSettings.EnableBackgroundAutoCompression = False)
61+
Public Property EnableBackgroundWatcherCommand As ICommand = New RelayCommand(Sub() AppSettings.EnableBackgroundWatcher = True)
62+
Public Property OpenGitHubCommand As ICommand = New RelayCommand(Sub() Process.Start(New ProcessStartInfo("https://github.com/IridiumIO/CompactGUI") With {.UseShellExecute = True}))
63+
Public Property OpenKoFiCommand As ICommand = New RelayCommand(Sub() Process.Start(New ProcessStartInfo("https://ko-fi.com/IridiumIO") With {.UseShellExecute = True}))
64+
65+
End Class

0 commit comments

Comments
 (0)