Skip to content

Commit

Permalink
Dev Commit
Browse files Browse the repository at this point in the history
[ Fixes ]
- Fixed where the Error Message wont pop up if the location is invalid or the config is none.
- Fixed where if the location selected has a name "config.ini" but its not the actual game will crash unexpectedly.
- Fixed where if the 1st or 2nd game has an invalid location while the 3rd game isn't
causes the 3rd game side button still grayed out.

[ Changes ]
- Moved the hyperlink routed events to a seperate file.
  • Loading branch information
IchimakiKasura committed Jun 17, 2023
1 parent b8fd9f8 commit 948291d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 63 deletions.
26 changes: 18 additions & 8 deletions src/HoyoLauncher.Core/Config/ConfigRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace HoyoLauncher.Core.Config;
public sealed class ConfigRead
{
// I like how the "GameInstallPath" and the "GameBackgroundName" isn't being used on other methods
public bool FilePathNone = false;
public bool ConfigExist = false;
public bool FilePathNone { get; private set; } = false;
public bool ConfigExist { get; private set; } = false;
public string GameInstallPath { get; private set; }
public string GameBackgroundName { get; private set; }
public string GameStartName { get; private set; }
Expand All @@ -17,6 +17,8 @@ public static ConfigRead GetConfig(string FilePath)
ImageBrush GameBG_TEMP = null;

const string grp = "launcher";
string gamepath, gamebg, gamename;

var ConfigFile = Path.Combine(FilePath, "config.ini");
bool configexist = File.Exists(ConfigFile);

Expand All @@ -35,16 +37,24 @@ public static ConfigRead GetConfig(string FilePath)
var DataObject = File.ReadAllText(Path.Combine(FilePath, "config.ini"));
var ParsedObject = new IniDataParser().Parse(DataObject);

var gamepath = ParsedObject[grp]["game_install_path"];
var gamebg = ParsedObject[grp]["game_dynamic_bg_name"];
var gamename = ParsedObject[grp]["game_start_name"];
try
{
gamepath = ParsedObject[grp]["game_install_path"];
gamebg = ParsedObject[grp]["game_dynamic_bg_name"];
gamename = ParsedObject[grp]["game_start_name"];
}
catch
{
return new()
{
ConfigExist = false
};
}

var CheckBGExist = Path.Combine(FilePath, "bg", gamebg);

if(File.Exists(CheckBGExist))
{
GameBG_TEMP = new(new BitmapImage(new(Path.Combine(FilePath, "bg", gamebg), UriKind.RelativeOrAbsolute)));
}

return new()
{
Expand All @@ -54,5 +64,5 @@ public static ConfigRead GetConfig(string FilePath)
GameStartName = Path.Combine(gamepath, gamename),
GameBackground = GameBG_TEMP
};
}
}
}
34 changes: 12 additions & 22 deletions src/HoyoLauncher.Core/HoyoMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,17 @@ public static void Initialize()
{
UpdateConfig();

bool ErrorOccured = false;

FirstRun = true;
CurrentGameSelected = HoyoGames.DEFAULT;
IsGameRunning = false;

EventsAttribute.SetEvents();

List<(string config, HoyoGames AbsoluteName, HoyoButton Launcher)> GameConfigs = new()
{
(AppSettings.Settings.Default.GENSHIN_IMPACT_DIR, HoyoGames.GenshinImpact, HoyoWindow.GENSHIN_IMPACT_LAUNCHER),
(AppSettings.Settings.Default.HONKAI_STAR_RAIL_DIR, HoyoGames.HonkaiStarRail, HoyoWindow.HONKAI_STAR_RAIL_LAUNCHER),
(AppSettings.Settings.Default.HONKAI_IMPACT_THIRD_DIR, HoyoGames.HonkaiImpactThird, HoyoWindow.HONKAI_IMPACT_THIRD_LAUNCHER)
};

foreach(var (config, name, Launcher) in CollectionsMarshal.AsSpan(GameConfigs))
{
ValidateSettings(config, name, Launcher, out ErrorOccured);
if(ErrorOccured) break;
}
ValidateSettings(AppSettings.Settings.Default.GENSHIN_IMPACT_DIR, HoyoGames.GenshinImpact, HoyoWindow.GENSHIN_IMPACT_LAUNCHER, out bool _);
ValidateSettings(AppSettings.Settings.Default.HONKAI_STAR_RAIL_DIR, HoyoGames.HonkaiStarRail, HoyoWindow.HONKAI_STAR_RAIL_LAUNCHER, out bool _);
ValidateSettings(AppSettings.Settings.Default.HONKAI_IMPACT_THIRD_DIR, HoyoGames.HonkaiImpactThird, HoyoWindow.HONKAI_IMPACT_THIRD_LAUNCHER, out bool _);

if(!ErrorOccured)
LastGame();
LastGame();
}

public static void GameChange(string uid) =>
Expand All @@ -71,8 +59,7 @@ public static void GameChange(short uid)
values.LaunchButton = false;
values.LaunchButtonContent = AppResources.Resources.GAME_SOON_TEXT;
}

if(!GameConfig.ConfigExist && CurrentGameSelected != HoyoGames.ZenlessZoneZero)
else if(!GameConfig.ConfigExist)
{
values.LaunchButton = false;
values.LaunchButtonContent = AppResources.Resources.GAME_NOTFOUND;
Expand Down Expand Up @@ -114,9 +101,6 @@ public static void ValidateSettings(string GameConfigName, HoyoGames Game, HoyoB
return;
}

if(!FirstRun)
MessageBox.Show($"ERROR:\n\nThe \"{Game.GAME_NAME}\" config cannot be found!\n or its an incorrect game.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

LauncherButton.IsEnabled = false;
}

Expand Down Expand Up @@ -175,7 +159,13 @@ public static void ProcessStart(string FileName) =>
public static string GenerateMD5HASH()
{
using var md5 = System.Security.Cryptography.MD5.Create();
using var stream = File.OpenRead(Environment.ProcessPath);

#if DEBUG
using var stream = File.OpenRead(Assembly.GetExecutingAssembly().Location);
#else
using var stream = File.OpenRead(Environment.ProcessPath);
#endif

return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-","");
}

Expand Down
8 changes: 4 additions & 4 deletions src/HoyoLauncherSettings/HoyoSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

<Grid>
<Border Name="Button_Location" Background="#f6f5f3" Margin="40,101,660,390" CornerRadius="10,10,0,0">
<TextBlock Text="Locations" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Segoe ui"/>
<TextBlock Text="Locations" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Segoe ui"/>
</Border>
<Border Name="Button_Others" Background="#e3e1de" Margin="161,101,539,390" CornerRadius="10,10,0,0">
<TextBlock Text="Others" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Segoe ui"/>
<TextBlock Text="Others" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Segoe ui"/>
</Border>
<Border Name="Button_About" Background="#e3e1de" Margin="282,101,418,390" CornerRadius="10,10,0,0">
<TextBlock Text="About" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Segoe ui"/>
<TextBlock Text="About" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="18" FontFamily="Segoe ui"/>
</Border>
</Grid>

Expand Down Expand Up @@ -88,7 +88,7 @@
<Hyperlink Click="GithubPR">Contribute on the Project</Hyperlink>
</TextBlock>
<Image Source="/Resources/HoyoVerseIcon.png" Stretch="Fill" Cursor="Hand" Height="130" Width="130" Canvas.Top="-2" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<Image Name="Github" Source="/Resources/github.png" Stretch="Fill" Cursor="Hand" Height="40" Canvas.Left="508" Width="40" Canvas.Top="252" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Image Source="/Resources/github.png" MouseDown="GithubIconButton" Stretch="Fill" Cursor="Hand" Height="40" Canvas.Left="508" Width="40" Canvas.Top="252" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Canvas>
</Grid>
</Border>
Expand Down
51 changes: 22 additions & 29 deletions src/HoyoLauncherSettings/HoyoSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ public partial class HoyoSettings : Window
{

// Hear me out, I'm kinda lazy when making the Button_Location etc.. so fuck the mess

Brush SelectedPageColor = new BrushConverter().ConvertFromString("#f6f5f3") as Brush;
Brush UnSelectedPageColor = new BrushConverter().ConvertFromString("#e3e1de") as Brush;
readonly Brush SelectedPageColor = new BrushConverter().ConvertFromString("#f6f5f3") as Brush;
readonly Brush UnSelectedPageColor = new BrushConverter().ConvertFromString("#e3e1de") as Brush;

public HoyoSettings()
{
Expand All @@ -17,13 +16,10 @@ public HoyoSettings()

HoyoWindow.BLACK_THING.Opacity = 0.5;

WindowDrag.MouseDown += (s, e) => { if (e.ChangedButton is MouseButton.Left) DragMove(); };
WindowDrag.MouseDown += (s, e) => { };
ExitButton.Click += (s, e) => Close();
CancelButton.Click += (s, e) => Close();

Github.MouseDown += (s,e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher");

RadioButtonTray.IsChecked = AppSettings.Settings.Default.MinimizedTray;

RadioButtonTray_Click.MouseDown += (s, e) =>
Expand All @@ -32,9 +28,9 @@ public HoyoSettings()
AppSettings.Settings.Default.MinimizedTray = (bool)(RadioButtonTray.IsChecked = !RadioButtonTray.IsChecked);
};

Button_Location.MouseDown += (s, e) => ChangePage(e, location: Visibility.Visible);
Button_Others.MouseDown += (s, e) => ChangePage(e, others: Visibility.Visible);
Button_About.MouseDown += (s, e) => ChangePage(e, about: Visibility.Visible);
Button_Location.MouseDown += (s, e) => ChangePage(e, location: 0);
Button_Others.MouseDown += (s, e) => ChangePage(e, others: 0);
Button_About.MouseDown += (s, e) => ChangePage(e, about: 0);
}

private void OnLoaded(object sender, RoutedEventArgs e)
Expand All @@ -54,7 +50,7 @@ static void GetFolderDirectory(TextBox txt)
{
using var Folder = new Forms.FolderBrowserDialog();

if(Folder.ShowDialog() == Forms.DialogResult.Cancel)
if(Folder.ShowDialog() is Forms.DialogResult.Cancel)
return;

txt.Text = Folder.SelectedPath;
Expand All @@ -67,22 +63,6 @@ void HSRClick(object s, RoutedEventArgs e) =>
void HI3Click(object s, RoutedEventArgs e) =>
GetFolderDirectory(HI3_DIR_TXT);

void GithubHome(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura");
void GithubLicense(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher/blob/master/LICENSE");
void GithubProject(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher");
void GithubPR(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher/pulls");
void GithubIssue(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher/issues");

void MihoyoPage(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://www.mihoyo.com/en/");
void HoyoversePage(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://www.hoyoverse.com/en-us/");

void ConfirmClick(object s, RoutedEventArgs e)
{
bool ErrorOccured = false;
Expand All @@ -96,8 +76,13 @@ void ConfirmClick(object s, RoutedEventArgs e)

foreach(var (config, name, Launcher) in CollectionsMarshal.AsSpan(GameConfigs))
{
HoyoMain.ValidateSettings(config, name, Launcher, out ErrorOccured);
if(ErrorOccured) break;
HoyoMain.ValidateSettings(config, name, Launcher, out bool IsInvalidGame);

if(IsInvalidGame)
{
MessageBox.Show($"ERROR:\n\nThe \"{name.GAME_NAME}\" config cannot be found!\n or its an incorrect game.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
ErrorOccured = true;
}
}

AppSettings.Settings.Default.GENSHIN_IMPACT_DIR = GI_DIR_TXT.Text;
Expand All @@ -106,6 +91,8 @@ void ConfirmClick(object s, RoutedEventArgs e)
AppSettings.Settings.Default.Save();
HoyoGames.RefreshDirectory();

RefreshCurrentSelectedGame();

if(!ErrorOccured)
Close();
}
Expand All @@ -125,4 +112,10 @@ void ChangePage(MouseButtonEventArgs e,
Button_Others.Background = others is Visibility.Visible ? SelectedPageColor : UnSelectedPageColor;
Button_About.Background = about is Visibility.Visible ? SelectedPageColor : UnSelectedPageColor;
}

static void RefreshCurrentSelectedGame()
{
if(HoyoMain.CurrentGameSelected != HoyoGames.DEFAULT)
HoyoMain.GameChange(--AppSettings.Settings.Default.LAST_GAME);
}
}
23 changes: 23 additions & 0 deletions src/HoyoLauncherSettings/HyperLinkButtons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace HoyoLauncher.HoyoLauncherSettings;

public partial class HoyoSettings
{
void GithubHome(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura");
void GithubLicense(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher/blob/master/LICENSE");
void GithubProject(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher");
void GithubPR(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher/pulls");
void GithubIssue(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher/issues");

void MihoyoPage(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://www.mihoyo.com/en/");
void HoyoversePage(object s, RoutedEventArgs e) =>
HoyoMain.ProcessStart("https://www.hoyoverse.com/en-us/");

void GithubIconButton(object s, MouseButtonEventArgs e) =>
HoyoMain.ProcessStart("https://github.com/IchimakiKasura/HoyoLauncher");
}
1 change: 1 addition & 0 deletions src/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public MainWindow()
AppVersion.Text = App.Version;
#else
AppVersion.Text += $": test ver({App.Version})";
Console.WriteLine(App.UniqueHashBUILD);
#endif
}

Expand Down

0 comments on commit 948291d

Please sign in to comment.