Skip to content

Commit

Permalink
add ability to run the game
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRoller01 committed Jun 5, 2022
1 parent 63707ea commit ff291af
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
12 changes: 3 additions & 9 deletions n-launcher/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;

namespace n_launcher
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
{
}

}
33 changes: 24 additions & 9 deletions n-launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum LauncherStatus
/// </summary>
public partial class MainWindow : Window
{
private string SaveFile = "config.json";
private readonly string saveFile = "config.json";
private string username = "RoadRoller01";
private string token = "";
private MyData data;
Expand Down Expand Up @@ -129,9 +129,21 @@ void ReadSaveFile()
{


try
{
string jsonString = File.ReadAllText(saveFile);
data = JsonSerializer.Deserialize<MyData>(jsonString)!;
}
catch (FileNotFoundException)
{
data = new MyData();
data.username = username;
data.token = token;
data.Games = new Dictionary<string, string>();

File.WriteAllText(saveFile, JsonSerializer.Serialize(data, options));
}

string jsonString = File.ReadAllText(SaveFile);
data = JsonSerializer.Deserialize<MyData>(jsonString)!;


username = data.username;
Expand Down Expand Up @@ -178,6 +190,8 @@ private async void PlayButton_Click(object sender, RoutedEventArgs e)
case LauncherStatus.play:
// Play

String gameName = GamesList.SelectedItem.ToString();
System.Diagnostics.Process.Start(gamesPath + gameName + "/" + gameName + ".exe");

break;
case LauncherStatus.downloadGame:
Expand All @@ -193,7 +207,7 @@ private async void PlayButton_Click(object sender, RoutedEventArgs e)


string jsonString = JsonSerializer.Serialize(data, options);
File.WriteAllText(SaveFile, jsonString);
File.WriteAllText(saveFile, jsonString);
Status = LauncherStatus.play;
break;
case LauncherStatus.downloadUpdate:
Expand Down Expand Up @@ -224,17 +238,18 @@ private async void GamesList_SelectionChanged(object sender, System.Windows.Cont
else if (savedGameVer == default)
{
Status = LauncherStatus.downloadGame;
} else
}
else
{
await DownloadGame(new Uri(latestRelease.Assets[0].BrowserDownloadUrl));


data.Games.Remove(selectedGameRep.Name);
data.Games.Add(selectedGameRep.Name, latestRelease.TagName);


string jsonString = JsonSerializer.Serialize(data, options);
File.WriteAllText(SaveFile, jsonString);
File.WriteAllText(saveFile, jsonString);
}
}

Expand Down
10 changes: 3 additions & 7 deletions n-launcher/MyData.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace n_launcher
{
class MyData
{
public string username { get; set; }
public string token { get; set; }
public Dictionary<string,string> Games { get; set; }
public Dictionary<string, string> Games { get; set; }

}
}
1 change: 0 additions & 1 deletion n-launcher/n-launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFramework>net6.0-windows</TargetFramework>
<RootNamespace>n_launcher</RootNamespace>
<UseWPF>true</UseWPF>
<ApplicationIcon />
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit ff291af

Please sign in to comment.