Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
craftersmine committed Jul 4, 2022
1 parent 77ce727 commit 09ab493
Show file tree
Hide file tree
Showing 95 changed files with 5,337 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/Build
Binary file added IconSource.psd
Binary file not shown.
Binary file added Icons/LockScreenLogo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icons/SplashScreen.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icons/Square150x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icons/Square44x44Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Icons/Wide310x150Logo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions craftersmine.AppLauncher.LauncherBridge/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
41 changes: 41 additions & 0 deletions craftersmine.AppLauncher.LauncherBridge/Common/FileExistsData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace craftersmine.AppLauncher.Common
{
public class FileExistsData
{
public List<FileDirData> FilesAndDirs = new List<FileDirData>();

public static FileExistsData DeserializeFromString(string str)
{
XmlSerializer serializer = new XmlSerializer(typeof(FileExistsData));
using (StringReader reader = new StringReader(str))
{
return serializer.Deserialize(reader) as FileExistsData;
}
}

public string SerializeToString()
{
XmlSerializer serializer = new XmlSerializer(typeof(FileExistsData));
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, this);
return writer.ToString();
}
}
}

public class FileDirData
{
public string Path { get; set; }
public bool Exists { get; set; }
public bool IsDirectory { get; set; }
}
}
72 changes: 72 additions & 0 deletions craftersmine.AppLauncher.LauncherBridge/Common/IPCClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using craftersmine.AppLauncher.Common;
using tiesky.com;

namespace craftersmine.AppLauncher.LauncherBridgeClient.Common
{
public class IPCClient
{
private SharmIpc ipc;

public event EventHandler<RemoteCallEventArgs> RemoteCall;

public IPCClient(string ipcPipeName)
{
ipc = new SharmIpc(ipcPipeName, _remoteCall);
}

private Tuple<bool, byte[]> _remoteCall(byte[] data)
{
string[] dataStr = Encoding.Default.GetString(data).Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(Encoding.Default.GetString(data));
RemoteCall?.Invoke(this, new RemoteCallEventArgs() { Data = Encoding.Default.GetString(data) });
string header = dataStr[0];
string payload = "";
if (dataStr.Length > 1)
payload = dataStr[1];

switch (header)
{
case "APPLAUNCH":
UserApp app = UserApp.DeserializeFromString(payload);
Program.ProcessManager = new ProcessManager(app);
Program.ProcessManager.Run();
return new Tuple<bool, byte[]>(true, Encoding.Default.GetBytes("APPLAUNCHED::" + app.SerializeToString()));
case "CHECKFILESEXISTANCE":
FileExistsData fileData = FileExistsData.DeserializeFromString(payload);
foreach (var fileOrDir in fileData.FilesAndDirs)
{
if (fileOrDir.IsDirectory)
fileOrDir.Exists = Directory.Exists(fileOrDir.Path);
else fileOrDir.Exists = File.Exists(fileOrDir.Path);
}
Program.DelayedExit();
return new Tuple<bool, byte[]>(true, Encoding.Default.GetBytes("FILESEXISTANCEDATA::" + fileData.SerializeToString()));
case "CLOSEAPP":
Program.ProcessManager.Close();
return new Tuple<bool, byte[]>(true, null);
case "TERMINATEAPP":
Program.ProcessManager.Kill();
return new Tuple<bool, byte[]>(true, null);
}

return new Tuple<bool, byte[]>(false, null);
}

public void SendProcessExited(string appUuid, int exitCode)
{
string procExitInfo = new ProcessExitedInformation(appUuid, exitCode).ToString();
ipc.RemoteRequestWithoutResponse(Encoding.Default.GetBytes("APPEXITED::" + procExitInfo));
}
}

public class RemoteCallEventArgs : EventArgs
{
public string Data { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace craftersmine.AppLauncher.LauncherBridgeClient.Common
{
public class ProcessExitedInformation
{
public string Uuid { get; set; }
public int ExitCode { get; set; }

public ProcessExitedInformation() { }

public ProcessExitedInformation(string uuid, int exitCode)
{
Uuid = uuid;
ExitCode = exitCode;
}

public override string ToString()
{
XmlSerializer serializer = new XmlSerializer(typeof(ProcessExitedInformation));
using (StringWriter writer = new StringWriter())
{
serializer.Serialize(writer, this);
return writer.ToString();
}
}
}
}
116 changes: 116 additions & 0 deletions craftersmine.AppLauncher.LauncherBridge/Common/ProcessManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace craftersmine.AppLauncher.LauncherBridgeClient.Common
{
public sealed class ProcessManager
{
private Process currentProcess;

public UserApp CurrentApp { get; set; }
public int ExitCode
{
get {
try
{
return currentProcess != null ? currentProcess.ExitCode : 0;
}
catch (Exception e)
{
return 0;
}
}
}
public bool Exited { get {
try
{
return currentProcess != null ? currentProcess.HasExited : true;
}
catch (Exception e)
{
return true;
}
} }

public ProcessManager(UserApp app)
{
CurrentApp = app;

ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.Arguments = CurrentApp.LaunchArguments;
processStartInfo.FileName = CurrentApp.ExecutablePath;
processStartInfo.WorkingDirectory = CurrentApp.WorkingDirectory;
processStartInfo.UseShellExecute = true;

if (app.RunAsAdmin)
processStartInfo.Verb = "runas";

currentProcess = new Process();
currentProcess.StartInfo = processStartInfo;
currentProcess.EnableRaisingEvents = true;
currentProcess.Exited += CurrentProcess_Exited;
}

private void CurrentProcess_Exited(object sender, EventArgs e)
{
Program.IPCClient.SendProcessExited(CurrentApp.Uuid, ExitCode);
Program.Exit();
}

private bool DetectExecutable()
{
// TODO: Implement executable location detection
return true;
}

private bool DetectWorkingDir()
{
// TODO: Implement working directory location detection
return true;

}

public void Run()
{
try
{
currentProcess.Start();
}
catch (Exception e)
{
Program.IPCClient.SendProcessExited(CurrentApp.Uuid, ExitCode);
Program.Exit();
}
}

public void Close()
{
try
{
currentProcess.Close();
}
catch (Exception e)
{
Program.IPCClient.SendProcessExited(CurrentApp.Uuid, ExitCode);
Program.Exit();
}
}

public void Kill()
{
try
{
currentProcess.Kill();
}
catch (Exception e)
{
Program.IPCClient.SendProcessExited(CurrentApp.Uuid, ExitCode);
Program.Exit();
}
}
}
}
41 changes: 41 additions & 0 deletions craftersmine.AppLauncher.LauncherBridge/Common/UserApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace craftersmine.AppLauncher.LauncherBridgeClient.Common
{
public class UserApp
{
[XmlAttribute]
public string Name { get; set; }
[XmlAttribute]
public string Uuid { get; set; }
public string ExecutablePath { get; set; }
public string LaunchArguments { get; set; }
public string WorkingDirectory { get; set; }
public bool RunAsAdmin { get; set; }

public static UserApp DeserializeFromString(string data)
{
XmlSerializer serializer = new XmlSerializer(typeof(UserApp));
using (TextReader tReader = new StringReader(data))
{
return serializer.Deserialize(tReader) as UserApp;
}
}

public string SerializeToString()
{
XmlSerializer serializer = new XmlSerializer(typeof(UserApp));
using (StringWriter tWriter = new StringWriter())
{
serializer.Serialize(tWriter, this);
return tWriter.ToString();
}
}
}
}
74 changes: 74 additions & 0 deletions craftersmine.AppLauncher.LauncherBridge/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 09ab493

Please sign in to comment.