-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chaniru Rajapakse
committed
May 23, 2022
1 parent
bd4d5ff
commit 3525d78
Showing
42 changed files
with
3,198 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<RootNamespace>Client_Launcher</RootNamespace> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace Client_Launcher | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello World!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using System; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
namespace ClientLauncher | ||
{ | ||
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 = ""; | ||
using (StreamReader sr = File.OpenText(Path.Combine(path, "StartInfo.xml"))) | ||
{ | ||
var s = sr.BaseStream; | ||
|
||
XmlReaderSettings settings = new XmlReaderSettings(); | ||
settings.Async = true; | ||
using (XmlReader reader = XmlReader.Create(s, settings)) | ||
{ | ||
reader.Read(); | ||
reader.ReadStartElement("Process"); | ||
reader.ReadToFollowing("StartInfo"); | ||
arguements = reader.GetAttribute("Arguments"); | ||
fileName = reader.GetAttribute("FileName"); | ||
workdir = reader.GetAttribute("WorkingDirectory"); | ||
reader.Close(); | ||
} | ||
try | ||
{ | ||
s.Close(); | ||
sr.Close(); | ||
} | ||
catch | ||
{ | ||
|
||
} | ||
} | ||
//Console.WriteLine(arguements); | ||
//Console.WriteLine(fileName); | ||
//Console.WriteLine(workdir); | ||
var info = new ProcessStartInfo { FileName = fileName, Arguments = arguements, WorkingDirectory = workdir }; | ||
var proc = new Process { StartInfo = info }; | ||
var processUtil = new ProcessUtil(proc); | ||
processUtil.OutputReceived += (s, e) => Console.WriteLine(e); | ||
processUtil.StartWithEvents(); | ||
proc.WaitForExit(); | ||
} | ||
static string GetEnviromentVar(string variableName) | ||
{ | ||
return Environment.GetEnvironmentVariable(variableName); | ||
} | ||
} | ||
public class ProcessUtil | ||
{ | ||
public event EventHandler<string>? OutputReceived; | ||
public event EventHandler? Exited; | ||
|
||
public Process Process { get; private set; } | ||
|
||
public ProcessUtil(Process process) | ||
{ | ||
this.Process = process; | ||
} | ||
|
||
public void StartWithEvents() | ||
{ | ||
Process.StartInfo.CreateNoWindow = true; | ||
Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; | ||
Process.StartInfo.UseShellExecute = false; | ||
Process.StartInfo.RedirectStandardError = true; | ||
Process.StartInfo.RedirectStandardOutput = true; | ||
Process.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; | ||
Process.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; | ||
Process.EnableRaisingEvents = true; | ||
Process.ErrorDataReceived += (s, e) => OutputReceived?.Invoke(this, e.Data ?? ""); | ||
Process.OutputDataReceived += (s, e) => OutputReceived?.Invoke(this, e.Data ?? ""); | ||
Process.Exited += (s, e) => Exited?.Invoke(this, new EventArgs()); | ||
|
||
Process.Start(); | ||
Process.BeginErrorReadLine(); | ||
Process.BeginOutputReadLine(); | ||
} | ||
|
||
public Task WaitForExitTaskAsync() | ||
{ | ||
return Task.Run(() => | ||
{ | ||
Process.WaitForExit(); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Windows.Storage; | ||
using System.Threading.Tasks; | ||
using System.Diagnostics; | ||
using Windows.Storage.Streams; | ||
using System.IO; | ||
using System.Xml; | ||
|
||
namespace SDLauncher_UWP.Converters | ||
{ | ||
public class ProcessToXmlConverter | ||
{ | ||
public async static Task Convert(Process Process,StorageFolder Destination,string FileName) | ||
{ | ||
var inf = Process.StartInfo; | ||
var storagefile = await Destination.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); | ||
using (IRandomAccessStream writestream = await storagefile.OpenAsync(FileAccessMode.ReadWrite)) | ||
{ | ||
Stream s = writestream.AsStreamForWrite(); | ||
XmlWriterSettings settings = new XmlWriterSettings(); | ||
settings.Async = true; | ||
settings.NewLineOnAttributes = false; | ||
settings.Indent = true; | ||
using (XmlWriter writer = XmlWriter.Create(s, settings)) | ||
{ | ||
writer.WriteStartDocument(); | ||
writer.WriteStartElement("Process"); | ||
writer.WriteStartElement("StartInfo"); | ||
writer.WriteAttributeString("Arguments", inf.Arguments); | ||
writer.WriteAttributeString("FileName", inf.FileName); | ||
writer.WriteAttributeString("WorkingDirectory", inf.WorkingDirectory); | ||
writer.WriteEndElement(); | ||
writer.WriteEndElement(); | ||
writer.Flush(); | ||
await writer.FlushAsync(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Data; | ||
|
||
namespace SDLauncher_UWP.Converters | ||
{ | ||
public class StringToVisibility : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, string language) | ||
{ | ||
// Reversed result | ||
if (parameter is string param) | ||
{ | ||
if (param == "0") | ||
{ | ||
return (value is string val && val.Length > 0) ? Visibility.Collapsed : Visibility.Visible; | ||
} | ||
} | ||
|
||
return (value is string str && str.Length > 0) ? Visibility.Visible : Visibility.Collapsed; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, string language) | ||
{ | ||
throw new InvalidOperationException("Use the boolean to visibility converter in this situation. " + | ||
"A string is very likely unnecessary in this case."); | ||
} | ||
} | ||
|
||
public class BindlessStringToVisibility | ||
{ | ||
public static Visibility BindlessConvert(object value) | ||
{ | ||
return (value is string str && str.Length > 0) ? Visibility.Visible : Visibility.Collapsed; | ||
} | ||
|
||
public static void BindlessConvertBack(object value) | ||
{ | ||
throw new InvalidOperationException("Use the boolean to visibility converter in this situation." + | ||
"A string is very likely unnecessary in this case. You tried to convert: " + value.ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.