Skip to content

Commit

Permalink
add discord for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
akbaryahya committed Sep 25, 2022
1 parent 60cde9f commit 472f2b8
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 37 deletions.
82 changes: 82 additions & 0 deletions Extra/Discord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using DiscordRPC;
using DiscordRPC.Logging;
using Button = DiscordRPC.Button;

namespace YuukiPS_Launcher.Extra
{
public class Discord
{
public DiscordRpcClient client;

public void Ready(string appid = "1023479009335582830")
{
if (client == null)
{
client = new DiscordRpcClient(appid);
client.Logger = new ConsoleLogger() { Level = LogLevel.Warning };
client.RegisterUriScheme();

//Subscribe to events
client.OnReady += (sender, e) =>
{
Console.WriteLine("Received Ready from user {0}", e.User.Username);
UpdateStatus("Getting ready", "Wait");
};
client.OnPresenceUpdate += (sender, e) =>
{
Console.WriteLine("Received Update! {0}", e.Presence);
};

//Connect to the RPC
client.Initialize();
}

}

public void UpdateStatus(string details, string state, string iconkey = "")
{
if (client != null)
{
var Editor = new RichPresence()
{
Details = details,
State = state
};
if (!string.IsNullOrEmpty(iconkey))
{
Editor.Assets = new Assets()
{
LargeImageKey = iconkey,
LargeImageText = state
};
}
else
{
Editor.Assets = new Assets()
{
LargeImageKey = "yuuki",
LargeImageText = "YuukiPS"
};
}
if (state.Contains("In Game"))
{
Editor.Buttons = new Button[]
{
new Button() { Label = "Join", Url = "https://ps.yuuki.me/" }
};
}
client.SetPresence(Editor);
}

}

public void Stop()
{
if (client != null)
{
client.Dispose();
client = null;
}
}
}
}
64 changes: 29 additions & 35 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,32 @@ namespace YuukiPS_Launcher
{
public partial class Main : Form
{

// Main Function
private ProxyController? proxy;
private Process? progress;

// Server List
Thread thServerList;
List<List> ListServer;

// https://nightly.link/akbaryahya/YuukiPS-Launcher/actions/runs/2947968074/YuukiPS.zip
// https://api.github.com/repos/akbaryahya/YuukiPS-Launcher/actions/artifacts

// Folder
public static string CurrentlyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "");

private static string DataConfig = Path.Combine(CurrentlyPath, "data");
private static string Modfolder = Path.Combine(CurrentlyPath, "mod");

// TODO: hapus nanti ini


// TODO: hapus nanti ini
//string PathfileGame = "";
//string PathMetadata = "";
//string PathUA = "";

//string DL_Patch = "";

// Config default
string VersionGame = "";
string WatchFile = "";
bool IsGameRun = false;
bool DoneCheck = true;
bool ShouldIcheck = false;

int GameMode = 0; // 0 - tanpa patch, 1 - patch
int GameChannel = 0;
int GameMetode = 1;

// Extra
Extra.Discord discord = new Extra.Discord();

public Main()
{
InitializeComponent();
Expand All @@ -53,19 +45,25 @@ private void Main_Load(object sender, EventArgs e)
{
Console.WriteLine("Loading....");

// Create missing Files
// Create missing folder
Directory.CreateDirectory(DataConfig);
Directory.CreateDirectory(Modfolder);

// Before starting make sure proxy is turned off
CheckProxy(true);

// Check Update
CheckUpdate();

// Check Game Version
CheckVersionGame();

// Server List
GetServerList();
UpdateServerListTimer();

// Extra
discord.Ready();
}

public bool CheckVersionGame()
Expand Down Expand Up @@ -201,6 +199,7 @@ public bool CheckVersionGame()
Console.WriteLine("File Game: " + PathfileGame);

Console.WriteLine("MD5 Game Currently: " + Game_LOC_Original_MD5);

return true;
}

Expand Down Expand Up @@ -932,29 +931,24 @@ public void CheckUpdate()
private static string GetLauncherPath(String version = "Genshin Impact")
{
RegistryKey key = Registry.LocalMachine;

if (key == null)
if (key != null)
{
return "";
}

var tes1 = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + version); // 原神
if (tes1 != null)
{
var testes1 = tes1.GetValue("InstallPath");
if (testes1 != null)
var tes1 = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + version);
if (tes1 != null)
{
var testestestes1 = testes1.ToString();
if (testestestes1 != null)
var testes1 = tes1.GetValue("InstallPath");
if (testes1 != null)
{
return testestestes1;
}
var testestestes1 = testes1.ToString();
if (testestestes1 != null)
{
return testestestes1;
}

}
}
}

return "";

}

// Check Game Install
Expand Down Expand Up @@ -1267,6 +1261,7 @@ private void CheckGameRun_Tick(object sender, EventArgs e)
Console.WriteLine(tes);
}
DoneCheck = true;
discord.UpdateStatus("Not playing", "Stop", "sleep");
}
}
else
Expand All @@ -1275,7 +1270,7 @@ private void CheckGameRun_Tick(object sender, EventArgs e)
IsGameRun = true;
btStart.Text = "Stop";
DoneCheck = false;
ShouldIcheck = true;
discord.UpdateStatus("Currently in Server " + GetHost.Text, "In Game", "on");
}
}

Expand Down Expand Up @@ -1461,7 +1456,6 @@ private void CheckProxyRun_Tick(object sender, EventArgs e)
[Obsolete]
void CheckProxy(bool force_off = false)
{
// Before starting make sure proxy is turned off
try
{
// Metode 1
Expand Down
5 changes: 3 additions & 2 deletions YuukiPS Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<ApplicationManifest>Properties\app.manifest</ApplicationManifest>

<AssemblyVersion>2022.9.21.2303</AssemblyVersion>
<FileVersion>2022.9.21.2303</FileVersion>
<AssemblyVersion>2022.9.25.0720</AssemblyVersion>
<FileVersion>2022.9.25.0720</FileVersion>

<EnableWindowsTargeting>true</EnableWindowsTargeting>
<AssemblyName>YuukiPS</AssemblyName>
Expand Down Expand Up @@ -45,6 +45,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
<PackageReference Include="Downloader" Version="2.4.1" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down

0 comments on commit 472f2b8

Please sign in to comment.