Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,4 @@ FodyWeavers.xsd
# IntelliJ
.idea/
/CompactGUI.WatcherCS
/.history
6 changes: 5 additions & 1 deletion CompactGUI/Application.xaml.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Imports System.IO
Imports System.IO
Imports System.IO.Pipes
Imports System.Threading
Imports System.Windows.Threading
Expand Down Expand Up @@ -31,7 +31,11 @@ Partial Public Class Application

End Sub

Private Sub Application_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
' Call the language configuration at startup
LanguageHelper.Initialize()

End Sub
Private Shared Sub InitializeHost()

_host = Host.CreateDefaultBuilder() _
Expand Down
18 changes: 17 additions & 1 deletion CompactGUI/CompactGUI.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<DebugType>none</DebugType>
</PropertyGroup>


<ItemGroup>
<Import Include="System.Windows" />
<Import Include="System.Windows.Controls" />
Expand All @@ -46,6 +45,7 @@
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
<PackageReference Include="Coravel" Version="6.0.2" />
<PackageReference Include="diskdetector-net" Version="0.3.2" />
<PackageReference Include="FunctionalConverters" Version="0.1.0" />
<PackageReference Include="Gameloop.Vdf" Version="0.6.2" />
<PackageReference Include="IridiumIO.MVVM.VBSourceGenerators" Version="0.6.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.7" />
Expand All @@ -71,6 +71,22 @@
</Reference>
</ItemGroup>

<ItemGroup>
<Compile Update="i18n\i18n.Designer.vb">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>i18n.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="i18n\i18n.resx">
<CustomToolNamespace>i18n</CustomToolNamespace>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>i18n.Designer.vb</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<Target Name="RenamePublishedExe" AfterTargets="Publish" Condition="'$(IsMonolithic)' == 'true'">
<Move SourceFiles="$(PublishDir)CompactGUI.exe" DestinationFiles="$(PublishDir)CompactGUI.mono.exe" />

Expand Down
23 changes: 12 additions & 11 deletions CompactGUI/Components/Converters/IValueConverters.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Imports System.Globalization
Imports System.Globalization

Public Class DecimalToPercentageConverter : Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert
Expand Down Expand Up @@ -88,20 +88,21 @@ End Class

Public Class RelativeDateConverter : Implements IValueConverter
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.Convert

Dim dt = CType(value, DateTime)
Dim ts As TimeSpan = DateTime.Now - dt

If ts > TimeSpan.FromDays(19000) Then
Return String.Format("Unknown")
Return LanguageHelper.GetString("Time_Unknown")
End If
If ts > TimeSpan.FromDays(2) Then
Return String.Format("{0:0} days ago", ts.TotalDays)
Return String.Format(LanguageHelper.GetString("Time_DaysAgo"), ts.TotalDays)
ElseIf ts > TimeSpan.FromHours(2) Then
Return String.Format("{0:0} hours ago", ts.TotalHours)
Return String.Format(LanguageHelper.GetString("Time_HoursAgo"), ts.TotalHours)
ElseIf ts > TimeSpan.FromMinutes(2) Then
Return String.Format("{0:0} minutes ago", ts.TotalMinutes)
Return String.Format(LanguageHelper.GetString("Time_MinutesAgo"), ts.TotalMinutes)
Else
Return "just now"
Return LanguageHelper.GetString("Time_Now")
End If
End Function

Expand Down Expand Up @@ -290,15 +291,15 @@ Public Class FolderStatusToStringConverter : Implements IValueConverter
Dim status = CType(value, ActionState)
Select Case status
Case ActionState.Idle
Return "Awaiting Compression"
Return LanguageHelper.GetString("Status_AwaitingCompression")
Case ActionState.Analysing
Return "Analysing"
Return LanguageHelper.GetString("Status_Analysing")
Case ActionState.Working, ActionState.Paused
Return "Working"
Return LanguageHelper.GetString("Status_Working")
Case ActionState.Results
Return "Compressed"
Return LanguageHelper.GetString("Status_Compressed")
Case Else
Return "Unknown"
Return LanguageHelper.GetString("Status_Unknown")
End Select
End Function
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Expand Down
11 changes: 7 additions & 4 deletions CompactGUI/Components/Settings/Settings_skiplistflyout.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ui:FluentWindow x:Class="Settings_skiplistflyout"
<ui:FluentWindow x:Class="Settings_skiplistflyout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand Down Expand Up @@ -45,7 +45,8 @@
<Grid x:Name="MainGrid">
<ui:TitleBar Panel.ZIndex="10"
ShowMaximize="False" ShowMinimize="False" />
<TextBlock Text="edit skipped filetypes"
<TextBlock Text="{local:Localize SetFiletypeManagement_LocalSkipFiletypesEdit}"
d:Text="edit skipped filetypes"
Margin="10"
FontSize="22" FontWeight="SemiBold" />
<local:TokenizedTextBox x:Name="UiTokenizedText"
Expand All @@ -64,12 +65,14 @@
</local:TokenizedTextBox>

<Button x:Name="UiSave"
Content="Save"
Content="{local:Localize UniSave}"
d:Content="Save"
Width="100"
Margin="0,0,130,20" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Click="UISave_Click" />
<Button x:Name="UiReset"
Content="Reset"
Content="{local:Localize UniReset}"
d:Content="Reset"
Width="100"
Margin="0,0,10,20" HorizontalAlignment="Right" VerticalAlignment="Bottom"
Click="UIReset_Click" />
Expand Down
139 changes: 139 additions & 0 deletions CompactGUI/LanguageHelper.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Imports System.Globalization
Imports System.Resources
Imports System.Threading
Imports System.Windows.Markup
Imports System.Windows.Data
Imports System.Reflection

Public Class LanguageHelper
' Supported language list
' @i18n
Private Shared ReadOnly SupportedCultures As String() = {"en-US", "zh-CN"}
Private Shared resourceManager As ResourceManager = i18n.i18n.ResourceManager
Private Shared currentCulture As CultureInfo = Nothing

Public Shared Function GetText(key As String) As String
Return GetString(key)
End Function

Public Shared Sub Initialize()
Dim savedLanguage As String = ReadAppConfig("language")
If Not String.IsNullOrEmpty(savedLanguage) AndAlso SupportedCultures.Contains(savedLanguage) Then
ApplyCulture(savedLanguage)
Else
SetDefaultLanguage()
End If
End Sub

Public Shared Sub ChangeLanguage()
If currentCulture Is Nothing Then
currentCulture = Thread.CurrentThread.CurrentUICulture
End If
Dim currentLang As String = currentCulture.Name
Dim nextLang As String = GetNextLanguage(currentLang)

ApplyCulture(nextLang)
WriteAppConfig("language", nextLang)
End Sub

Public Shared Function GetString(key As String, ParamArray args As Object()) As String
Try
Dim cultureToUse = If(currentCulture, Thread.CurrentThread.CurrentUICulture)
Dim rawValue As String = resourceManager.GetString(key, cultureToUse)

If String.IsNullOrEmpty(rawValue) Then
Return key
ElseIf args IsNot Nothing AndAlso args.Length > 0 Then
Return String.Format(cultureToUse, rawValue, args)
Else
Return rawValue
End If
Catch ex As Exception
Debug.WriteLine($"Failed to get multilingual text:{key},Error:{ex.Message}")
Return key
End Try
End Function

Public Shared Sub ApplyCulture(cultureName As String)
Try
Dim culture As New CultureInfo(cultureName)
Thread.CurrentThread.CurrentUICulture = culture
Thread.CurrentThread.CurrentCulture = culture
currentCulture = culture

Catch ex As Exception
Debug.WriteLine($"Application language failure:{cultureName},Error:{ex.Message}")
SetDefaultLanguage()
End Try
End Sub

Private Shared Function GetNextLanguage(currentLanguage As String) As String
Dim currentTwoLetter = New CultureInfo(currentLanguage).TwoLetterISOLanguageName
For i As Integer = 0 To SupportedCultures.Length - 1
Dim langTwoLetter = New CultureInfo(SupportedCultures(i)).TwoLetterISOLanguageName
If langTwoLetter = currentTwoLetter Then
Return SupportedCultures((i + 1) Mod SupportedCultures.Length)
End If
Next
Return SupportedCultures(0)
End Function

Private Shared Sub SetDefaultLanguage()
' Set the default language according to the system language.
'@i18n
Dim langMapping As New Dictionary(Of String, String) From {
{"en", "en-US"},
{"zh", "zh-CN"}
}

Dim systemLang As String = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName.ToLower()
Dim defaultLang As String = If(langMapping.ContainsKey(systemLang), langMapping(systemLang), "en-US")

ApplyCulture(defaultLang)
WriteAppConfig("language", defaultLang)
End Sub

Public Shared Function GetCurrentLanguage() As String
Return If(currentCulture, Thread.CurrentThread.CurrentUICulture).Name
End Function

Public Shared Function ReadAppConfig(key As String) As String
Try
Dim config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None)
Return If(config.AppSettings.Settings(key)?.Value, String.Empty)
Catch ex As Exception
Debug.WriteLine($"Read configuration failed:{key},Error:{ex.Message}")
Return String.Empty
End Try
End Function

Public Shared Sub WriteAppConfig(key As String, value As String)
Try
Dim config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None)
If config.AppSettings.Settings(key) IsNot Nothing Then
config.AppSettings.Settings(key).Value = value
Else
config.AppSettings.Settings.Add(key, value)
End If
config.Save(System.Configuration.ConfigurationSaveMode.Modified)
System.Configuration.ConfigurationManager.RefreshSection("appSettings")
Catch ex As Exception
Debug.WriteLine($"Write configuration failed:{key},Error:{ex.Message}")
End Try
End Sub
End Class

<MarkupExtensionReturnType(GetType(String))>
Public Class LocalizeExtension
Inherits MarkupExtension

Private _key As String

Public Sub New(key As String)
_key = key
End Sub

Public Overrides Function ProvideValue(serviceProvider As IServiceProvider) As Object
Return LanguageHelper.GetString(_key)
End Function
End Class
19 changes: 11 additions & 8 deletions CompactGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ui:FluentWindow x:Class="MainWindow"
<ui:FluentWindow x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:bh="http://schemas.microsoft.com/xaml/behaviors"
Expand Down Expand Up @@ -41,7 +41,8 @@
<ui:NavigationView.MenuItems>


<ui:NavigationViewItem Content="Home"
<ui:NavigationViewItem Content="{local:Localize Title_Home}"
d:Content="Home"
Margin="15,2,15,10"
NavigationCacheMode="Required"
Tag="{Binding}"
Expand All @@ -52,7 +53,8 @@
</ui:NavigationViewItem>


<ui:NavigationViewItem Content="Watcher"
<ui:NavigationViewItem Content="{local:Localize Title_Watcher}"
d:Content="Watcher"
Margin="15,2,15,10"
NavigationCacheMode="Required"
Tag="{Binding}"
Expand All @@ -62,7 +64,8 @@
</ui:NavigationViewItem.Icon>
</ui:NavigationViewItem>

<ui:NavigationViewItem Content="Compression DB"
<ui:NavigationViewItem Content="{local:Localize Title_CompressionDB}"
d:Content="Compression DB"
Margin="15,2,15,10"
NavigationCacheMode="Disabled"
Tag="{Binding}"
Expand Down Expand Up @@ -231,14 +234,14 @@
</Style>
</Label.Style>
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock Text="CompactGUI"
<TextBlock Text="{local:Localize Title_CompactGUI}" d:Text="CompactGUI"
Margin="0,0,20,0" VerticalAlignment="Center"
Foreground="#20FFFFFF"
Visibility="{Binding IsAdmin, Converter={StaticResource BooleanToInverseVisibilityConverter}}" />
<Border Width="80" Height="22"
Background="#20f44336" CornerRadius="10"
Visibility="{Binding IsAdmin, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock Text="Admin"
<TextBlock Text="{local:Localize UniAdmin}" d:Text="Admin"
HorizontalAlignment="Center" VerticalAlignment="Center"
Foreground="White" />

Expand All @@ -256,8 +259,8 @@
FocusOnLeftClick="True" MenuOnRightClick="True" TooltipText="CompactGUI">
<tray:NotifyIcon.Menu>
<ContextMenu x:Name="NotifyIconTrayMenu">
<MenuItem Command="{Binding NotifyIconOpenCommand}" Header="Open" />
<MenuItem Command="{Binding NotifyIconExitCommand}" Header="Exit" />
<MenuItem Command="{Binding NotifyIconOpenCommand}" Header="{local:Localize UniOpen}" />
<MenuItem Command="{Binding NotifyIconExitCommand}" Header="{local:Localize UniExit}" />
</ContextMenu>
</tray:NotifyIcon.Menu>
</tray:NotifyIcon>
Expand Down
4 changes: 2 additions & 2 deletions CompactGUI/Models/CompressableFolders/CompressableFolder.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Imports System.Collections.ObjectModel
Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Threading

Expand All @@ -10,7 +10,7 @@ Imports CompactGUI.Core.WOFHelper

Imports Microsoft.Extensions.Logging

Imports PropertyChanged
'Imports PropertyChanged


'Need this abstract class so we can use it in XAML
Expand Down
4 changes: 2 additions & 2 deletions CompactGUI/Services/CompressableFolderService.vb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Imports System.Collections.ObjectModel
Imports System.Collections.ObjectModel
Imports System.Threading

Imports CompactGUI.Core
Imports CompactGUI.Core.Settings

Imports Microsoft.CodeAnalysis.Diagnostics
'Imports Microsoft.CodeAnalysis.Diagnostics

Imports Microsoft.Extensions.Logging

Expand Down
Loading