This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
77ce727
commit 09ab493
Showing
95 changed files
with
5,337 additions
and
0 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 |
---|---|---|
|
@@ -348,3 +348,4 @@ MigrationBackup/ | |
|
||
# Ionide (cross platform F# VS Code tools) working folder | ||
.ionide/ | ||
/Build |
Binary file not shown.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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
41
craftersmine.AppLauncher.LauncherBridge/Common/FileExistsData.cs
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,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
72
craftersmine.AppLauncher.LauncherBridge/Common/IPCClient.cs
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,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; } | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
craftersmine.AppLauncher.LauncherBridge/Common/ProcessExitedInformation.cs
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,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
116
craftersmine.AppLauncher.LauncherBridge/Common/ProcessManager.cs
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.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(); | ||
} | ||
} | ||
} | ||
} |
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,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(); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.