Skip to content

Commit

Permalink
version 0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaniru Rajapakse committed May 28, 2022
1 parent 3525d78 commit 1d0d406
Show file tree
Hide file tree
Showing 23 changed files with 731 additions and 192 deletions.
49 changes: 32 additions & 17 deletions ClientLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,13 @@ class Program
{
static void Main(string[] args)
{

if (args.Length > 2)
{
if (args[2] == "/admin")
{
string aliasPath =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory +
@"\ClientLauncher.exe");

ProcessStartInfo Restartinfo = new ProcessStartInfo();
Restartinfo.Verb = "runas";
Restartinfo.UseShellExecute = true;
Restartinfo.FileName = aliasPath;
Process.Start(Restartinfo);
return;
}
}
Console.Title = "SDLauncher Loging System";
var l = GetEnviromentVar("LocalAppData");
var path = Path.Combine(l, @"Packages\SeaDevs.Launcher.UWP_0dk3ndwmrga1t\LocalState");
string arguements = "";
string fileName = "";
string workdir = "";
string logs = "";
using (StreamReader sr = File.OpenText(Path.Combine(path, "StartInfo.xml")))
{
var s = sr.BaseStream;
Expand All @@ -46,6 +30,7 @@ static void Main(string[] args)
reader.ReadToFollowing("StartInfo");
arguements = reader.GetAttribute("Arguments");
fileName = reader.GetAttribute("FileName");
logs = reader.GetAttribute("GameLogs");
workdir = reader.GetAttribute("WorkingDirectory");
reader.Close();
}
Expand All @@ -59,6 +44,36 @@ static void Main(string[] args)

}
}

if (args.Length > 2)
{
if (args[2] == "/admin")
{
string appPath =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory +
@"\ClientLauncher.exe");

ProcessStartInfo Restartinfo = new ProcessStartInfo();
Restartinfo.Verb = "runas";
if(logs != "True")
{
Restartinfo.WindowStyle = ProcessWindowStyle.Hidden;
Restartinfo.CreateNoWindow = true;
}
Restartinfo.UseShellExecute = true;
Restartinfo.FileName = appPath;
try
{
Process.Start(Restartinfo);
}
catch
{
Console.WriteLine("User Cancelled the request...");
Console.ReadLine();
}
return;
}
}
//Console.WriteLine(arguements);
//Console.WriteLine(fileName);
//Console.WriteLine(workdir);
Expand Down
19 changes: 16 additions & 3 deletions SDLauncher UWP/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,20 @@ protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
await settings.CreateSettingsFile(false);
}
await settings.LoadSettingsFile();
try
{
await settings.LoadSettingsFile();
}
catch
{
vars.CurrentRam = 2048;
try
{
await settings.CreateSettingsFile(false);
await settings.LoadSettingsFile();
}
catch { }
}
}
else
{
Expand All @@ -80,7 +93,7 @@ protected async override void OnLaunched(LaunchActivatedEventArgs e)
{
//TODO: Load state from previously suspended application
}
rootFrame.RequestedTheme = (ElementTheme)vars.theme;
rootFrame.RequestedTheme = (ElementTheme)vars.Theme;
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
Expand Down Expand Up @@ -137,7 +150,7 @@ protected async override void OnActivated(IActivatedEventArgs args)
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.RequestedTheme = (ElementTheme)vars.theme;
rootFrame.RequestedTheme = (ElementTheme)vars.Theme;
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
Expand Down
Binary file added SDLauncher UWP/Assets/BackDrops/Transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions SDLauncher UWP/Converters/ProcessToXmlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public async static Task Convert(Process Process,StorageFolder Destination,strin
writer.WriteStartElement("StartInfo");
writer.WriteAttributeString("Arguments", inf.Arguments);
writer.WriteAttributeString("FileName", inf.FileName);
writer.WriteAttributeString("GameLogs", vars.GameLogs.ToString());
writer.WriteAttributeString("WorkingDirectory", inf.WorkingDirectory);
writer.WriteEndElement();
writer.WriteEndElement();
Expand Down
8 changes: 4 additions & 4 deletions SDLauncher UWP/Dialogs/Login.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private async void btnMSLogin_Click(object sender, RoutedEventArgs e)
var x = new MSLogin();
UI(false);
btnMSLogin.Content = "Please wait";
await x.Initialize();
x.Initialize();
var result = await x.Login();
if (result == MSLogin.Exceptions.Cancelled)
{
Expand Down Expand Up @@ -164,12 +164,12 @@ private void txtbxOffUsername_KeyDown(object sender, KeyRoutedEventArgs e)
private void ContentDialog_Loaded(object sender, RoutedEventArgs e)
{
btnBack_Click(null, null);
if (vars.theme != null)
if (vars.Theme != null)
{
if (Window.Current.Content is FrameworkElement fe)
{
this.RequestedTheme = (ElementTheme)vars.theme;
fe.RequestedTheme = (ElementTheme)vars.theme;
this.RequestedTheme = (ElementTheme)vars.Theme;
fe.RequestedTheme = (ElementTheme)vars.Theme;
}
}
UpdateAccounts();
Expand Down
2 changes: 1 addition & 1 deletion SDLauncher UWP/Dialogs/MessageBoxEx.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public MessageBoxEx(string title, string caption, MessageBoxButtons buttons)
PrimaryButtonText = "Yes";
SecondaryButtonText = "No";
}
this.RequestedTheme = (ElementTheme)vars.theme;
this.RequestedTheme = (ElementTheme)vars.Theme;
}
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
Expand Down
115 changes: 115 additions & 0 deletions SDLauncher UWP/Helpers/GlacierClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using SDLauncher_UWP.Resources;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage;
using Windows.UI.Xaml;

namespace SDLauncher_UWP.Helpers
{
public class GlacierClient
{
public event EventHandler<SDLauncher.ProgressChangedEventArgs> ProgressChanged = delegate { };
public event EventHandler StatusChanged = delegate { };
public event EventHandler DownloadCompleted = delegate { };
public event EventHandler UIChangedReqested = delegate { };
public async Task<bool> ClientExists()
{
try
{
var verFolder = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Versions);
var mcVerFolder = await verFolder.GetFolderAsync("Glacier Client");
return true;
}
catch
{
return false;
}
}
public async void DownloadClient()
{
UIChangedReqested(false, new EventArgs());
try
{
Uri source = new Uri("https://slashonline.net/glacier/get/release/Glacier.zip".Trim());
string destination = "Glacier.zip";

StorageFile destinationFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(
destination,
CreationCollisionOption.ReplaceExisting);

BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
StartDownloadWithProgress(download);
}
catch
{

}
}
DownloadOperation operation;
DispatcherTimer downloadprog = new DispatcherTimer();
private async void StartDownloadWithProgress(DownloadOperation operation)
{
StatusChanged("Downloading Glacier Client", new EventArgs());
this.operation = operation;
await this.operation.StartAsync();
downloadprog.Interval = new TimeSpan(0, 0, 0, 0, 1);
downloadprog.Tick += Downloadprog_Tick;
downloadprog.Start();
}


private void Downloadprog_Tick(object sender, object e)
{
if (operation.Progress.Status == BackgroundTransferStatus.Completed)
{
DownloadFileCompleted();
downloadprog.Stop();
ProgressChanged(0, new SDLauncher.ProgressChangedEventArgs(currentfile:0));
}
else if (operation.Progress.Status == BackgroundTransferStatus.Running)
{
try
{
double bytesIn = operation.Progress.BytesReceived;
double totalBytes = operation.Progress.TotalBytesToReceive;
ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentfile: unchecked((int)bytesIn), maxfiles: unchecked((int)totalBytes)));
}
catch { }
StatusChanged("Downloading Glacier Client", new EventArgs());
}
else if (operation.Progress.Status == BackgroundTransferStatus.Error)
{
DownloadCompleted(false, new EventArgs());
downloadprog.Stop();
}
}

private async void DownloadFileCompleted()
{
UIChangedReqested(false, new EventArgs());
StatusChanged("Extracting", new EventArgs());

//Read the file stream
var wf = await StorageFolder.GetFolderFromPathAsync(vars.Launcher.Launcher.MinecraftPath.Versions);
var f = await wf.CreateFolderAsync("Glacier Client", CreationCollisionOption.ReplaceExisting);
var a = await ApplicationData.Current.TemporaryFolder.GetFileAsync("Glacier.zip");
Stream b = await a.OpenStreamForReadAsync();
//unzip
ZipArchive archive = new ZipArchive(b);
archive.ExtractToDirectory(f.Path, true);

ProgressChanged(this, new SDLauncher.ProgressChangedEventArgs(currentfile:0));
StatusChanged(Localized.Ready, new EventArgs());
UIChangedReqested(true, new EventArgs());
DownloadCompleted(true, new EventArgs());
}

}
}
2 changes: 1 addition & 1 deletion SDLauncher UWP/Helpers/MSLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum Exceptions
Cancelled,
ConnectFailed
}
public async Task Initialize()
public void Initialize()
{
app = MsalMinecraftLoginHelper.CreateDefaultApplicationBuilder("ff127655-b402-4ca7-815f-b878147837ad").Build();
handler = new MsalMinecraftLoginHandler(app);
Expand Down
38 changes: 22 additions & 16 deletions SDLauncher UWP/Helpers/OptiFine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ public void DownloadOptiFineVer(string mcver, string modVer, string DisplayVer)
switch (mcver)
{
case "1.18.2":
returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
optver = ": " + mcver;
OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.18.2.zip", "OptiFine-" + mcver + ".zip", ModType.ver);
break;
case "1.18.1":
returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
optver = ": " + mcver;
OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.18.1.zip", "OptiFine-" + mcver + ".zip", ModType.ver);
break;
case "1.17.1":
returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
optver = ": " + mcver;
OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.17.1.zip", "OptiFine-" + mcver + ".zip", ModType.ver);
break;
case "1.16.5":
returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.DownloadOptiFineVer);
optver = ": " + mcver;
OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/OptiFine-1.16.5.zip", "OptiFine-" + mcver + ".zip", ModType.ver);
break;
Expand All @@ -106,7 +106,7 @@ public async Task<OptFineVerReturns> CheckOptiFine(string mcver, string modVer,
}
if (exists)
{
returns = new OptFineVerReturns(modVer, DisplayVer, OptFineVerReturns.Results.Exists);
returns = new OptFineVerReturns(modVer, mcver, DisplayVer, OptFineVerReturns.Results.Exists);
UIChangedReqested(true, new EventArgs());
return returns;
}
Expand All @@ -120,15 +120,15 @@ public async Task<OptFineVerReturns> CheckOptiFine(string mcver, string modVer,
{
if (await IsOptiFineFilePresent(null, null, true))
{
returns = new OptFineVerReturns(null, null, OptFineVerReturns.Results.DownloadOptiFineVer);
returns = new OptFineVerReturns(modVer, mcver, "Version", OptFineVerReturns.Results.DownloadOptiFineVer);
UIChangedReqested(true, new EventArgs());
return returns;
}
else
{
await MessageBox.Show("Information", "This will download main OptiFine library, Please click again " + DisplayVer + " (after download and extract the main OptiFine) to install optifine of that version !", MessageBoxButtons.Ok);
optver = " Lib";
returns = new OptFineVerReturns(modVer, mcver, OptFineVerReturns.Results.DownloadOptiFineLib);
returns = new OptFineVerReturns(modVer, mcver, "Version", OptFineVerReturns.Results.DownloadOptiFineLib);
OptFineDownload("https://raw.githubusercontent.com/Chaniru22/SDLauncher/main/optifine.zip", "OptiFine.zip", ModType.lib);
UIChangedReqested(true, new EventArgs());
return returns;
Expand All @@ -137,18 +137,22 @@ public async Task<OptFineVerReturns> CheckOptiFine(string mcver, string modVer,
else
{
await MessageBox.Show("Error", "You have to install & run minecraft version " + mcver + " one time to install OptiFine", MessageBoxButtons.Ok);
returns = new OptFineVerReturns(mcver, mcver, OptFineVerReturns.Results.DownloadMCVer);
returns = new OptFineVerReturns(mcver, mcver,mcver, OptFineVerReturns.Results.DownloadMCVer);
UIChangedReqested(true, new EventArgs());
return returns;
}
}
else
{
returns = new OptFineVerReturns(modVer, mcver, "Version", OptFineVerReturns.Results.Failed);
UIChangedReqested(true, new EventArgs());
return returns;
}
}
UIChangedReqested(true, new EventArgs());
return returns;
}
else
{
returns = new OptFineVerReturns(null, null, OptFineVerReturns.Results.Failed);
returns = new OptFineVerReturns(modVer, mcver, "Version", OptFineVerReturns.Results.Failed);
UIChangedReqested(true, new EventArgs());
return returns;
}
Expand Down Expand Up @@ -263,13 +267,15 @@ public enum Results
DownloadMCVer,
Exists
}
public string LaunchVer { get; set; }
public string btnVer { get; set; }
public string MCVer { get; set; }
public string ModVer { get; set; }
public string DisplayVer { get; set; }
public Results Result { get; set; }
public OptFineVerReturns(string launchver, string btnver, Results result)
public OptFineVerReturns(string modver, string mcver, string displayver, Results result)
{
LaunchVer = launchver;
btnVer = btnver;
this.ModVer = modver;
this.MCVer = mcver;
DisplayVer = displayver;
Result = result;
}
}
Expand Down
Loading

0 comments on commit 1d0d406

Please sign in to comment.