Skip to content

Commit 5487bf0

Browse files
committed
vOS.sln fusion
2 parents 3b3ee4b + 39ff8a8 commit 5487bf0

21 files changed

+363
-117
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
using System;
2+
using System.Threading.Tasks;
3+
using vOS.API;
24

35
namespace vOS.Application.Echo
46
{
57
public class Program
68
{
7-
public static int Main(string[] args)
9+
public string Tag;
10+
11+
public int Main(string[] args)
812
{
13+
//var args = API.Application.Arguments;
14+
15+
System.Console.WriteLine(Tag);
16+
Tag = Guid.NewGuid().ToString();
17+
System.Console.WriteLine(Tag);
18+
919
args[0] = string.Empty;
1020

11-
Console.WriteLine(string.Join(" ", args));
21+
System.Console.WriteLine(string.Join(" ", args));
22+
23+
BackgroundSpin();
1224

1325
return 0;
1426
}
27+
28+
private async void BackgroundSpin()
29+
{
30+
while (true)
31+
{
32+
await Task.Delay(1000);
33+
System.Console.WriteLine(Tag);
34+
}
35+
}
1536
}
1637
}

Applications/Console/vOS.Application.Echo/vOS.Application.Echo.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<ProjectReference Include="..\..\..\System\vOS\vOS.csproj" />
11+
<ProjectReference Include="..\..\..\System\vOS.API\vOS.API.csproj" />
1212
</ItemGroup>
1313

1414
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace vOS.Application.iKVM
4+
{
5+
public class Program
6+
{
7+
public static int Main(string[] args)
8+
{
9+
10+
11+
return 0;
12+
}
13+
}
14+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="IKVM.Maven.Sdk" Version="1.0.0" />
9+
</ItemGroup>
10+
11+
</Project>

Hosts/vOS.UWP/Pages/vConsole.xaml.cs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public vConsole()
2121
var process = Process.Start("terminal", string.Join(" ", Environment.GetCommandLineArgs()));
2222
//process.WaitUntilExit();
2323
//Command.Send("terminal " + string.Join(" ", args));
24+
25+
2426
}
2527

2628
private void Write(string value) =>

System/vOS.API/Application.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace vOS.API
6+
{
7+
public static class Application
8+
{
9+
public static string[] Arguments { get; internal set; }
10+
}
11+
}

System/vOS.API/Console.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Text;
3+
4+
namespace vOS.API
5+
{
6+
public class Console
7+
{
8+
public static void Write(object value)
9+
{
10+
11+
}
12+
13+
public static void WriteLine(object value) =>
14+
Write(value + Environment.NewLine);
15+
16+
public static int Read()
17+
{
18+
//System.Diagnostics.Process.GetCurrentProcess()
19+
20+
return '\0';
21+
}
22+
23+
public static string ReadLine()
24+
{
25+
int key = '\0';
26+
StringBuilder line = new();
27+
28+
while (key != '\n')
29+
{
30+
key = Read();
31+
line.Append(key);
32+
33+
34+
}
35+
36+
return line.ToString();
37+
}
38+
}
39+
}

System/vOS.API/vOS.API.csproj

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>9.0</LangVersion>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\vOS\vOS.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

System/vOS.API/vOS_API_Init.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace vOS.API
6+
{
7+
public static class vOS_API_Init
8+
{
9+
private static Guid ProcessId;
10+
11+
public static string Tag;
12+
13+
public static int main(string[] arguments, Guid instance, Guid previousInstance, int windowState)
14+
{
15+
ProcessId = instance;
16+
Application.Arguments = arguments;
17+
18+
return 0;
19+
}
20+
}
21+
}

System/vOS/CollectibleAssemblyLoadContext.cs

-16
This file was deleted.

System/vOS/Command.cs

+77-12
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ internal static int Send(string command)
117117
throw new Exception("Can't open this file");
118118
}
119119
}
120+
catch (TargetInvocationException tie)
121+
{
122+
Console.WriteLine(tie.InnerException);
123+
}
120124
catch (Exception e)
121125
{
122126
Console.WriteLine("Execution failed: " + e.Message);
127+
if (e.InnerException != null)
128+
Console.WriteLine(e.InnerException.Message);
123129
}
124130

125131
return 1;
@@ -128,23 +134,44 @@ internal static int Send(string command)
128134
private static int ExecuteAssembly(Assembly assembly, string[] args)
129135
{
130136
var mains = GetMainsWithHelpAttribute(assembly);
137+
var mos = assembly.GetLoadedModules();
138+
139+
// No main
131140
if (mains.Count() < 1)
132141
throw new Exception("We can't execute this");
142+
143+
// Multi mains
133144
if (mains.Count() > 1)
134145
Console.WriteLine("Warning: more than one entry point exists");
135-
var main = mains.FirstOrDefault();
146+
147+
// Get the main
148+
var main = mains.First();
136149
object programReturn;
137150

151+
// Instanciate a class if needed
152+
object instance = null;
153+
154+
if (!main.IsStatic)
155+
instance = Activator.CreateInstance(main.DeclaringType);
156+
157+
// Start the app
138158
var parameters = main.GetParameters();
139-
if (parameters.Length == 1 && parameters[0].ParameterType == typeof(string[]))
140-
{
141-
programReturn = main.Invoke(null, new object[] { args });
142-
}
143-
else if (parameters.Length == 0)
144-
programReturn = main.Invoke(null, null);
145-
else
159+
160+
if (parameters.Length == 4 && // main(string[] arguments, Guid instance, Guid previousInstance, int windowState)
161+
parameters[0].ParameterType == typeof(string[]) &&
162+
parameters[1].ParameterType == typeof(Guid) &&
163+
parameters[2].ParameterType == typeof(Guid) &&
164+
parameters[3].ParameterType == typeof(int))
165+
programReturn = main.Invoke(instance, new object[] { args, Guid.NewGuid(), Guid.Empty, 0 }); // Invoke the main with the given arguments and window info
166+
else if (parameters.Length == 1 && // main(string[] arguments)
167+
parameters[0].ParameterType == typeof(string[]))
168+
programReturn = main.Invoke(instance, new object[] { args }); // Invoke the main with the given arguments
169+
else if (parameters.Length == 0) // main()
170+
programReturn = main.Invoke(instance, null); // Invoke the main without arguments
171+
else // Bad main, ex: main(int index, object value)
146172
throw new Exception("Bad Entry Point");
147173

174+
// Get exit code
148175
if (programReturn is int exitCode)
149176
return exitCode;
150177
else if (programReturn is Task<int> exitCodeAsync)
@@ -198,18 +225,28 @@ private static IEnumerable<MethodInfo> GetMainsWithHelpAttribute(Assembly assemb
198225
// https://docs.microsoft.com/dotnet/csharp/fundamentals/program-structure/main-command-line#overview
199226
private static bool CheckValidMainMethode(MethodInfo method)
200227
{
201-
// Must be static
228+
/*// Must be static
202229
if (!method.IsStatic)
203-
return false;
230+
return false;*/
204231

205232
// Must have the name Main
206233
if (method.Name.ToLower() != "main")
207234
return false;
208235

209236
// Must have 1 string parameter or not
210237
var parameters = method.GetParameters();
211-
if (parameters.Length == 1 && parameters[0].ParameterType != typeof(string[]) ||
212-
parameters.Length > 1)
238+
239+
if (// main(string[] arguments, Guid instance, Guid previousInstance, int windowState)
240+
parameters.Length == 4 &&
241+
parameters[0].ParameterType != typeof(string[]) &&
242+
parameters[1].ParameterType != typeof(Guid) &&
243+
parameters[2].ParameterType != typeof(Guid) &&
244+
parameters[3].ParameterType != typeof(int) ||
245+
// main(string[] arguments)
246+
parameters.Length == 1 &&
247+
parameters[0].ParameterType != typeof(string[]) ||
248+
// main()
249+
parameters.Length > 1)
213250
return false;
214251

215252
// Must return a integer or not
@@ -220,6 +257,34 @@ private static bool CheckValidMainMethode(MethodInfo method)
220257
return true;
221258
}
222259

260+
/*private static bool CheckValidApiMethode(MethodInfo method)
261+
{
262+
// Must be static
263+
if (!method.IsStatic)
264+
return false;
265+
266+
// Must have the name vOS_Init
267+
if (method.Name != "vOS_Main")
268+
return false;
269+
270+
// Must have 1 string parameter or not
271+
var parameters = method.GetParameters();
272+
273+
// vOS_Main(Guid instance, Guid previousInstance, string commandLineArguments, int windowState)
274+
if (parameters.Length != 4 ||
275+
parameters[0].ParameterType != typeof(Guid) ||
276+
parameters[1].ParameterType != typeof(Guid) ||
277+
parameters[2].ParameterType != typeof(string) ||
278+
parameters[3].ParameterType != typeof(int))
279+
return false;
280+
281+
// Must return a integer
282+
if (method.ReturnType != typeof(int))
283+
return false;
284+
285+
return true;
286+
}*/
287+
223288
// http://www.blackbeltcoder.com/Articles/strings/a-c-command-line-parser
224289
// https://stackoverflow.com/questions/24047674/how-to-reset-position-in-stringreader-to-begining-of-string
225290
private static string[] CommandLineToArgs(string commandLine)

System/vOS/Device/DeviceType.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace vOS.Device
2+
{
3+
public enum DeviceType
4+
{
5+
Camera = 419,
6+
Battery = 670,
7+
Bluetooth = 745,
8+
GraphicCard = 861,
9+
NetworkCard = 559,
10+
Keyboard = 442,
11+
SoftwareComponent = 628,
12+
AudioVideoGameController = 135,
13+
USBController = 968,
14+
StorageController = 241,
15+
DriveController = 287,
16+
AudioIO = 147,
17+
PrintQueue = 684,
18+
Printer = 413,
19+
HMI = 927,
20+
DiskReader = 451,
21+
Firmware = 744,
22+
Monitor = 549,
23+
Computer = 639,
24+
SecurityDevice = 527,
25+
SoftwareDevice = 964,
26+
SystemDevice = 301,
27+
Processor = 382,
28+
/// <summary> Aka: Mouse </summary>
29+
PointingDevice = 165,
30+
Port = 309,
31+
}
32+
}

System/vOS/Device/IDevice.cs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace vOS.Device
2+
{
3+
public interface IDevice
4+
{
5+
string Name { get; }
6+
DeviceType Type { get; }
7+
}
8+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Text;
5+
6+
namespace vOS.Device
7+
{
8+
internal class SerialConsoleDevice : IDevice
9+
{
10+
public SerialConsoleDevice(string name, TextWriter tx, TextReader rx)
11+
{
12+
Name = name;
13+
Type = DeviceType.Port;
14+
Tx = tx;
15+
Rx = rx;
16+
}
17+
18+
public string Name { get; private set; }
19+
20+
public DeviceType Type { get; private set; }
21+
22+
public readonly TextWriter Tx;
23+
public readonly TextReader Rx;
24+
}
25+
}

0 commit comments

Comments
 (0)