Skip to content

Commit

Permalink
removed playtime (hotfix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plextora committed May 6, 2024
1 parent b342050 commit 494ddfb
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 51 deletions.
40 changes: 0 additions & 40 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public partial class MainWindow
public static bool IsDiscordPresenceEnabled;
public static bool IsHideToTrayEnabled;
public static bool IsCloseAfterInjectedEnabled;
public static string? SavedPlayTimeString;
public static TimeSpan ActualSavedPlayTime;

private static Stopwatch _timePlayed = new();

public MainWindow()
{
Expand Down Expand Up @@ -88,8 +84,6 @@ public MainWindow()
Updater.GetInjectorChangelog();
Updater.GetClientChangelog();

LoadTimePlayed();

_notifyIcon = new NotifyIcon();
if (GetLine(File.ReadAllText(SettingsWindow.ConfigFilePath), 4) == "firstrun:true")
{
Expand Down Expand Up @@ -233,7 +227,6 @@ private async void LaunchButton_OnLeftClick(object sender, RoutedEventArgs e)
Injector.Inject(Updater.DownloadDll());
IsMinecraftRunning = true;

_timePlayed.Start();
Minecraft.EnableRaisingEvents = true;
Minecraft.Exited += IfMinecraftExited;
}
Expand Down Expand Up @@ -276,7 +269,6 @@ private async void LaunchButton_OnRightClick(object sender, RoutedEventArgs e)
Injector.Inject(openFileDialog.FileName);
IsMinecraftRunning = true;

_timePlayed.Start();
Minecraft.EnableRaisingEvents = true;
Minecraft.Exited += IfMinecraftExited;
}
Expand All @@ -288,38 +280,6 @@ private static void IfMinecraftExited(object sender, EventArgs e)
Application.Current.Dispatcher.Invoke(SetStatusLabel.Default);
IsMinecraftRunning = false;
if (IsCustomDll) IsCustomDll = false;

// terrible play time code
_timePlayed.Stop();
TimeSpan currentTimeSpan = _timePlayed.Elapsed;
ActualSavedPlayTime += currentTimeSpan;
SaveTimePlayed(ActualSavedPlayTime);
LoadTimePlayed();
}

private static string GetTimePlayed(TimeSpan timePlayed)
{
double playTimeDecimals = ActualSavedPlayTime.TotalHours - Math.Truncate(ActualSavedPlayTime.TotalHours);
double playTimeMinutes = playTimeDecimals * 60;
return $"{Math.Truncate(ActualSavedPlayTime.TotalHours)}.{Math.Round(playTimeMinutes)}";
}

private static void SaveTimePlayed(TimeSpan timeSpan)
{
string textToWrite = Math.Round(timeSpan.TotalSeconds).ToString(CultureInfo.InvariantCulture);
SettingsWindow.ModifyConfig($"savedplaytime:{textToWrite}", 5);
}

private static void LoadTimePlayed()
{
SavedPlayTimeString = GetLine(File.ReadAllText(SettingsWindow.ConfigFilePath), 5);
SavedPlayTimeString = SavedPlayTimeString?.Replace("savedplaytime:", "");
ActualSavedPlayTime = TimeSpan.FromSeconds(Math.Round(Convert.ToDouble(SavedPlayTimeString)));
SavedPlayTimeString = TimeSpan.FromSeconds(Math.Round(Convert.ToDouble(SavedPlayTimeString))).ToString();
double playTimeDecimals = ActualSavedPlayTime.TotalHours - Math.Truncate(ActualSavedPlayTime.TotalHours);
double playTimeMinutes = playTimeDecimals * 60;
Application.Current.Dispatcher.Invoke(() => SettingsWindow.TimePlayedLabel.Content =
$"Total play time with Latite Client: {Math.Truncate(ActualSavedPlayTime.TotalHours)}.{Math.Round(playTimeMinutes)} hour(s)");
}

private void ChangelogButton_OnClick(object sender, RoutedEventArgs e)
Expand Down
7 changes: 0 additions & 7 deletions SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,6 @@
Foreground="AliceBlue"
IsChecked="False"
Style="{StaticResource CheckBox}" />
<Label
x:Name="TimePlayedLabel"
Margin="10,276,10,10"
x:FieldModifier="public"
Content="Total play time with Latite Client: "
FontSize="10"
Foreground="AliceBlue" />
</Grid>
</Border>
</Window>
4 changes: 1 addition & 3 deletions SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ private void ConfigSetup()
"discordstatus:true\n" +
"hidetotray:false\n" +
"closeafterinjected:false\n" +
"firstrun:true\n" +
"savedplaytime:00\n";
"firstrun:true\n";

File.WriteAllText(ConfigFilePath, defaultConfigText);

Expand All @@ -54,7 +53,6 @@ private void LoadConfig()
IsDiscordPresenceEnabled = GetLine(config, 1) == "discordstatus:true";
IsHideToTrayEnabled = GetLine(config, 2) == "hidetotray:true";
IsCloseAfterInjectedEnabled = GetLine(config, 3) == "closeafterinjected:true";
SavedPlayTimeString = GetLine(config, 5);
DiscordPresenceCheckBox.IsChecked = IsDiscordPresenceEnabled;
HideToTrayCheckBox.IsChecked = IsHideToTrayEnabled;
CloseAfterInjectedCheckBox.IsChecked = IsCloseAfterInjectedEnabled;
Expand Down
2 changes: 1 addition & 1 deletion Utils/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LatiteInjector.Utils;

public static class Updater
{
public const string InjectorCurrentVersion = "14";
public const string InjectorCurrentVersion = "15";

private const string INJECTOR_VERSION_URL =
"https://raw.githubusercontent.com/Imrglop/Latite-Releases/main/launcher_version";
Expand Down

0 comments on commit 494ddfb

Please sign in to comment.