Skip to content

Commit

Permalink
Localization support
Browse files Browse the repository at this point in the history
  • Loading branch information
gablm committed Jan 17, 2024
1 parent e38f8c9 commit 719e541
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 36 deletions.
19 changes: 9 additions & 10 deletions CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public static uint GenerateAppId(string exe, string appname)
return appId >> 32;
}

/*private uint GenerateGridId(string exe, string appname)
private static uint GenerateGridId(string exe, string appname)
{
uint appId = GeneratePreliminaryId(exe, appname);

return (appId >> 32) - 0x10000000;
}*/
}

public void MoveImages(string path, PresetConfigV2 preset)
{
Expand All @@ -126,18 +126,18 @@ public void MoveImages(string path, PresetConfigV2 preset)
SteamAssetCollection assets = preset.ZoneSteamAssets;

// Game background
CopyImage(gridPath, assets.Hero, "_hero");
GetImageFromUrl(gridPath, assets.Hero, "_hero");

// Game logo
CopyImage(gridPath, assets.Logo, "_logo");
GetImageFromUrl(gridPath, assets.Logo, "_logo");

// Vertical banner
// Shows when viewing all games of category or in the Home page
CopyImage(gridPath, assets.Banner, "p");
GetImageFromUrl(gridPath, assets.Banner, "p");

// Horizontal banner
// Appears in Big Picture mode when the game is the most recently played
CopyImage(gridPath, assets.Preview, "");
GetImageFromUrl(gridPath, assets.Preview, "");
}

private static string MD5Hash(string path)
Expand All @@ -150,15 +150,15 @@ private static string MD5Hash(string path)
return BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
}

private async void CopyImage(string gridPath, SteamAsset asset, string steamSuffix)
private async void GetImageFromUrl(string gridPath, SteamAsset asset, string steamSuffix)
{
string steamPath = Path.Combine(gridPath, preliminaryAppID + steamSuffix + ".png");

string hash = MD5Hash(steamPath);

if (hash.ToLower() == asset.MD5) return;

for (int i = 0; i < 2; i++)
for (int i = 0; i < 3; i++)
{
FileInfo info = new FileInfo(steamPath);
await DownloadImage(info, asset.URL, new CancellationToken());
Expand All @@ -170,10 +170,9 @@ private async void CopyImage(string gridPath, SteamAsset asset, string steamSuff
File.Delete(steamPath);

LogWriteLine(string.Format("Invalid checksum for file {0}! {1} does not match {2}.", steamPath, hash, asset.MD5), Hi3Helper.LogType.Error);
LogWriteLine("Trying again...", Hi3Helper.LogType.Error);
}

LogWriteLine("After two tries, " + asset.URL + " could not be downloaded successfully.", Hi3Helper.LogType.Error);
LogWriteLine("After 3 tries, " + asset.URL + " could not be downloaded successfully.", Hi3Helper.LogType.Error);
return;
}

Expand Down
42 changes: 21 additions & 21 deletions CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/SimpleDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -646,25 +646,25 @@ void CopyTextToClipboard(object sender, RoutedEventArgs e)
public static async Task<Tuple<ContentDialogResult, bool>> Dialog_ShortcutCreationConfirm(UIElement Content, string path)
{
StackPanel panel = new StackPanel { Orientation = Orientation.Vertical, MaxWidth = 500 };
panel.Children.Add(new TextBlock { Text = "A shortcut will be created in the following path:", Margin = new Thickness(0, 2, 0, 4), HorizontalAlignment = HorizontalAlignment.Center });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.ShortcutCreationConfirmSubtitle1, Margin = new Thickness(0, 2, 0, 4), HorizontalAlignment = HorizontalAlignment.Center });
TextBlock pathText = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 4) };
pathText.Inlines.Add(new Run() { Text = path, FontWeight = FontWeights.Bold });
panel.Children.Add(pathText);
panel.Children.Add(new TextBlock { Text = "If there is already a shortcut with the same name in this folder, it will be replaced.", TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 4), HorizontalAlignment = HorizontalAlignment.Center });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.ShortcutCreationConfirmSubtitle2, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 4), HorizontalAlignment = HorizontalAlignment.Center });

CheckBox playOnLoad = new CheckBox() {
Content = new TextBlock { Text = "Automatically start game after using this shortcut", TextWrapping = TextWrapping.Wrap },
Content = new TextBlock { Text = Lang._Dialogs.ShortcutCreationConfirmCheckBox, TextWrapping = TextWrapping.Wrap },
Margin = new Thickness(0, 4, 0, -8),
HorizontalAlignment = HorizontalAlignment.Center
};
panel.Children.Add(playOnLoad);

ContentDialogResult result = await SpawnDialog(
"Are you sure you want to continue?",
Lang._Dialogs.ShortcutCreationConfirmTitle,
panel,
Content,
Lang._Misc.Cancel,
"Yes, continue",
Lang._Misc.YesContinue,
dialogTheme: ContentDialogTheme.Warning
);

Expand All @@ -674,20 +674,20 @@ public static async Task<Tuple<ContentDialogResult, bool>> Dialog_ShortcutCreati
public static async Task<ContentDialogResult> Dialog_ShortcutCreationSuccess(UIElement Content, string path, bool play = false)
{
StackPanel panel = new StackPanel { Orientation = Orientation.Vertical, MaxWidth = 500 };
panel.Children.Add(new TextBlock { Text = "A shiny new shortcut was created!", HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 2, 0, 4) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.ShortcutCreationSuccessSubtitle1, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 2, 0, 4) });
TextBlock pathText = new TextBlock { HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 4) };
pathText.Inlines.Add(new Run() { Text = "Location: " });
pathText.Inlines.Add(new Run() { Text = Lang._Dialogs.ShortcutCreationSuccessSubtitle2 });
pathText.Inlines.Add(new Run() { Text = path, FontWeight = FontWeights.Bold });
panel.Children.Add(pathText);

if (play)
{
panel.Children.Add(new TextBlock { Text = "Notes:", FontWeight = FontWeights.Bold, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 8, 0, 4) });
panel.Children.Add(new TextBlock { Text = " • Using this shortcut will start the game after loading the region.", TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 2) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.ShortcutCreationSuccessSubtitle3, FontWeight = FontWeights.Bold, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 8, 0, 4) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.ShortcutCreationSuccessSubtitle4, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 2) });
}

return await SpawnDialog(
"Success!",
Lang._Dialogs.ShortcutCreationSuccessTitle,
panel,
Content,
Lang._Misc.Close,
Expand All @@ -699,23 +699,23 @@ public static async Task<Tuple<ContentDialogResult, bool>> Dialog_SteamShortcutC
{
StackPanel panel = new StackPanel { Orientation = Orientation.Vertical, MaxWidth = 500 };

panel.Children.Add(new TextBlock { Text = "A shortcut will be added to every Steam profile in this computer.", HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 2) });
panel.Children.Add(new TextBlock { Text = "If already added, the assets related to the shortcut will be verified.", HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 4) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationConfirmSubtitle1, HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 4, 0, 2) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationConfirmSubtitle2, HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 4) });

CheckBox playOnLoad = new CheckBox()
{
Content = new TextBlock { Text = "Automatically start game after using this shortcut", TextWrapping = TextWrapping.Wrap },
Content = new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationConfirmCheckBox, TextWrapping = TextWrapping.Wrap },
Margin = new Thickness(0, 4, 0, -8),
HorizontalAlignment = HorizontalAlignment.Center
};
panel.Children.Add(playOnLoad);

ContentDialogResult result = await SpawnDialog(
"Are you sure you want to continue?",
Lang._Dialogs.SteamShortcutCreationConfirmTitle,
panel,
Content,
Lang._Misc.Cancel,
"Yes, continue",
Lang._Misc.YesContinue,
dialogTheme: ContentDialogTheme.Warning
);

Expand All @@ -725,17 +725,17 @@ public static async Task<Tuple<ContentDialogResult, bool>> Dialog_SteamShortcutC
public static async Task<ContentDialogResult> Dialog_SteamShortcutCreationSuccess(UIElement Content, bool play = false)
{
StackPanel panel = new StackPanel { Orientation = Orientation.Vertical, MaxWidth = 500 };
panel.Children.Add(new TextBlock { Text = "A new shiny shortcut was added every Steam profile in this computer!", HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 4) });
panel.Children.Add(new TextBlock { Text = "Notes:", FontWeight = FontWeights.Bold, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 8, 0, 4) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationSuccessSubtitle1, HorizontalAlignment = HorizontalAlignment.Center, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 4) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationSuccessSubtitle2, FontWeight = FontWeights.Bold, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 8, 0, 4) });
if (play)
{
panel.Children.Add(new TextBlock { Text = " • Using this shortcut will start the game after loading the region.", TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 2) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationSuccessSubtitle3, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 2) });
}
panel.Children.Add(new TextBlock { Text = " • Running this process again will fix any corrupted/missing images belonging to the shortcut.", TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 2) });
panel.Children.Add(new TextBlock { Text = " • New shortcuts will only be shown after Steam is reloaded.", TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 4) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationSuccessSubtitle4, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 2) });
panel.Children.Add(new TextBlock { Text = Lang._Dialogs.SteamShortcutCreationSuccessSubtitle5, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 4) });

return await SpawnDialog(
"Success!",
Lang._Dialogs.SteamShortcutCreationSuccessTitle,
panel,
Content,
Lang._Misc.Close,
Expand Down
4 changes: 2 additions & 2 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -733,15 +733,15 @@
<Button.Content>
<StackPanel Orientation="Horizontal" Margin="4,0">
<TextBlock FontFamily="{ThemeResource FontAwesomeSolid}" Text="&#xf08e;" FontSize="18"/>
<TextBlock Text="Create shortcut" FontWeight="Medium" Margin="8,0,0,0"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._HomePage.GameSettings_Panel4CreateShortcutBtn}" FontWeight="Medium" Margin="8,0,0,0"/>
</StackPanel>
</Button.Content>
</Button>
<Button x:Name="AddToSteamButton" Margin="0,8" CornerRadius="14" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left" Click="AddToSteamButton_Click">
<Button.Content>
<StackPanel Orientation="Horizontal" Margin="4,0">
<TextBlock FontFamily="{ThemeResource FontAwesomeBrand}" Text="&#xf1b6;" FontSize="20"/>
<TextBlock Text="Add To Steam" FontWeight="Medium" Margin="8,0,0,0"/>
<TextBlock Text="{x:Bind helper:Locale.Lang._HomePage.GameSettings_Panel4AddToSteamBtn}" FontWeight="Medium" Margin="8,0,0,0"/>
</StackPanel>
</Button.Content>
</Button>
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ private async void AddToSteamButton_Click(object sender, RoutedEventArgs e)

private async void ShortcutButton_Click(object sender, RoutedEventArgs e)
{
string folder = await FileDialogNative.GetFolderPicker();
string folder = await FileDialogNative.GetFolderPicker(Lang._HomePage.CreateShortcut_FolderPicker);

if (string.IsNullOrEmpty(folder))
return;
Expand Down
19 changes: 19 additions & 0 deletions Hi3Helper.Core/Lang/Locale/LangDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ public sealed class LangDialogs
public string MeteredConnectionWarningSubtitle { get; set; } = LangFallback?._Dialogs.MeteredConnectionWarningSubtitle;
public string ResetKbShortcutsTitle { get; set; } = LangFallback?._Dialogs.ResetKbShortcutsTitle;
public string ResetKbShortcutsSubtitle { get; set; } = LangFallback?._Dialogs.ResetKbShortcutsSubtitle;
public string ShortcutCreationConfirmTitle { get; set; } = LangFallback?._Dialogs.ShortcutCreationConfirmTitle;
public string ShortcutCreationConfirmSubtitle1 { get; set; } = LangFallback?._Dialogs.ShortcutCreationConfirmSubtitle1;
public string ShortcutCreationConfirmSubtitle2 { get; set; } = LangFallback?._Dialogs.ShortcutCreationConfirmSubtitle2;
public string ShortcutCreationConfirmCheckBox { get; set; } = LangFallback?._Dialogs.ShortcutCreationConfirmCheckBox;
public string ShortcutCreationSuccessTitle { get; set; } = LangFallback?._Dialogs.ShortcutCreationSuccessTitle;
public string ShortcutCreationSuccessSubtitle1 { get; set; } = LangFallback?._Dialogs.ShortcutCreationSuccessSubtitle1;
public string ShortcutCreationSuccessSubtitle2 { get; set; } = LangFallback?._Dialogs.ShortcutCreationSuccessSubtitle2;
public string ShortcutCreationSuccessSubtitle3 { get; set; } = LangFallback?._Dialogs.ShortcutCreationSuccessSubtitle3;
public string ShortcutCreationSuccessSubtitle4 { get; set; } = LangFallback?._Dialogs.ShortcutCreationSuccessSubtitle4;
public string SteamShortcutCreationConfirmTitle { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationConfirmTitle;
public string SteamShortcutCreationConfirmSubtitle1 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationConfirmSubtitle1;
public string SteamShortcutCreationConfirmSubtitle2 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationConfirmSubtitle2;
public string SteamShortcutCreationConfirmCheckBox { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationConfirmCheckBox;
public string SteamShortcutCreationSuccessTitle { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationSuccessTitle;
public string SteamShortcutCreationSuccessSubtitle1 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationSuccessSubtitle1;
public string SteamShortcutCreationSuccessSubtitle2 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationSuccessSubtitle2;
public string SteamShortcutCreationSuccessSubtitle3 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationSuccessSubtitle3;
public string SteamShortcutCreationSuccessSubtitle4 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationSuccessSubtitle4;
public string SteamShortcutCreationSuccessSubtitle5 { get; set; } = LangFallback?._Dialogs.SteamShortcutCreationSuccessSubtitle5;
}
}
#endregion
Expand Down
3 changes: 3 additions & 0 deletions Hi3Helper.Core/Lang/Locale/LangHomePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public sealed class LangHomePage
public string GameSettings_Panel4 { get; set; } = LangFallback?._HomePage.GameSettings_Panel4;
public string GameSettings_Panel4ShowEventsPanel { get; set; } = LangFallback?._HomePage.GameSettings_Panel4ShowEventsPanel;
public string GameSettings_Panel4ShowSocialMediaPanel { get; set; } = LangFallback?._HomePage.GameSettings_Panel4ShowSocialMediaPanel;
public string GameSettings_Panel4CreateShortcutBtn { get; set; } = LangFallback?._HomePage.GameSettings_Panel4CreateShortcutBtn;
public string GameSettings_Panel4AddToSteamBtn { get; set; } = LangFallback?._HomePage.GameSettings_Panel4AddToSteamBtn;
public string CreateShortcut_FolderPicker { get; set; } = LangFallback?._HomePage.CreateShortcut_FolderPicker;
public string GamePlaytime_Panel1 { get; set; } = LangFallback?._HomePage.GamePlaytime_Panel1;
public string GamePlaytime_Idle_Panel1Hours { get; set; } = LangFallback?._HomePage.GamePlaytime_Idle_Panel1Hours;
public string GamePlaytime_Idle_Panel1Minutes { get; set; } = LangFallback?._HomePage.GamePlaytime_Idle_Panel1Minutes;
Expand Down
1 change: 1 addition & 0 deletions Hi3Helper.Core/Lang/Locale/LangMisc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public sealed class LangMisc
public string YesImReallySure { get; set; } = LangFallback?._Misc.YesImReallySure;
public string YesIHaveBeefyPC { get; set; } = LangFallback?._Misc.YesIHaveBeefyPC;
public string YesChangeLocation { get; set; } = LangFallback?._Misc.YesChangeLocation;
public string YesContinue { get; set; } = LangFallback?._Misc.YesContinue;
public string No { get; set; } = LangFallback?._Misc.No;
public string NoStartFromBeginning { get; set; } = LangFallback?._Misc.NoStartFromBeginning;
public string NoCancel { get; set; } = LangFallback?._Misc.NoCancel;
Expand Down
Loading

0 comments on commit 719e541

Please sign in to comment.