SunResearchInstitute / SwitchPresence-Rewritten

Nintendo Switch sysmodule server for PresenceClient!
https://link.sunthecourier.net/switchpresence
GNU General Public License v2.0
127 stars 15 forks source link

CLI-only version #18

Closed ioistired closed 4 years ago

ioistired commented 4 years ago

I ported the WinForms client to a CLI app. I did this to make it easier for me to run on startup as a Linux user, and I figure it'll be handy to Windows users who would like to run it as a service, as well. Here's my CLI port: https://github.com/iomintz/SwitchPresence-Rewritten/tree/cli-port

I'm wondering if this could somehow be integrated into the main project. Since both the GUI version and the CLI version are useful, the CLI version could be added as a separate folder in the tree, but that would introduce needless code duplication. Maybe this could work as an MVC app, with a view for the GUI and a view for the CLI?

gabehxd commented 4 years ago

Though i'm not very found of how it was implemented from a quick glance I believe I could create a sort of "shared library" that both the CLI and GUI version can both use thus removing lots of possible code duplication and put it into 2 separate projects files, keeping it cleaner than putting it all into one project file.

gabehxd commented 4 years ago

If you would like to help start on that it would be much appreciated :) (do make sure to pr it as a draft too!)

ioistired commented 4 years ago

I'm not sure I'm adept enough at C# for that. This port was my first time working with the language.

gabehxd commented 4 years ago

CLI SwitchPresence GUI SwitchPresence :)

Please do test I have no clue if they work lol.

ioistired commented 4 years ago
➤ mono SwitchPresence-CLI.exe
Cannot open assembly 'SwitchPresence-CLI.exe': File does not contain a valid CIL image.
➤ file SwitchPresence-CLI.exe 
SwitchPresence-CLI.exe: PE32+ executable (console) x86-64, for MS Windows
➤ chmod +x SwitchPresence-CLI.exe 
➤ ./SwitchPresence-CLI.exe 
0026:fixme:msvcrt:_configure_wide_argv (1) stub
0026:fixme:msvcrt:_initialize_wide_environment stub
A fatal error occurred. The required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [Z:\home\user\Downloads\SwitchPresence-Client\].
If this is a framework-dependent application, install the runtime in the global location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].
0026:fixme:advapi:RegisterEventSourceW ((null),L".NET Runtime"): stub
0026:fixme:advapi:ReportEventW (0xcafe4242,0x0001,0x0000,0x000003ff,(nil),0x0001,0x00000000,0x2afc90,(nil)): stub
0026:err:eventlog:ReportEventW L"Description: A .NET Core application failed.\nApplication: SwitchPresence-CLI.exe\nPath: Z:\\home\\user\\Downloads\\SwitchPresence-Client\\SwitchPresence-CLI.exe\nMessage: A fatal error occurred. The required library hostfxr.dll could not be found.\nIf this is a self-contained application"...
0026:fixme:advapi:DeregisterEventSource (0xcafe4242) stub

The one you gave me fails because it's not compiled for my platform. But compiling it myself works fine :+1:

gabehxd commented 4 years ago

The application was built with DotNet core so try downloading that and running it with dotnet instead

gabehxd commented 4 years ago

i'll double check my compilation setting as well

ioistired commented 4 years ago

How do I "run it with dotnet"? dotnet build produces native executables for me. I have dotnet core installed, since it works for me when I compile it myself. I don't need to run my compiled copy with dotnet or anything, just the path to the executable.

ioistired commented 4 years ago

The command I used is env FrameworkPathOverride=/usr/lib/mono/4.7.2-api/ dotnet build. I am using Arch Linux.

gabehxd commented 4 years ago

ah my bad it should be a 'publish' version

ioistired commented 4 years ago

What does that mean?

gabehxd commented 4 years ago

VS allows you to compile it into two different ways one of them being a publish version which out a dll instead of an exe iirc

ioistired commented 4 years ago

So is that an error on your end or something I need to change?

gabehxd commented 4 years ago

you should be running the dll in the zip with dotnet run

gabehxd commented 4 years ago

My bad that actually might only be for windows, try this one instead publish.zip

ioistired commented 4 years ago
/tmp/foo
➤ dotnet run SwitchPresence-CLI.dll
Couldn't find a project to run. Ensure a project exists in /tmp/foo, or pass the path to the project using --project.
/tmp/foo
➤ file SwitchPresence-CLI.exe
SwitchPresence-CLI.exe: PE32+ executable (console) x86-64, for MS Windows
/tmp/foo
➤ file SwitchPresence-CLI.dll
SwitchPresence-CLI.dll: PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows
/tmp/foo
➤ mono SwitchPresence-CLI.dll 

Unhandled Exception:
System.BadImageFormatException: Could not resolve field token 0x04000005, due to: Could not load type of field 'SwitchPresence_CLI.Program:timer' (0) due to: Could not resolve type with token 0100000d from typeref (expected class 'System.Timers.Timer' in assembly 'System.ComponentModel.TypeConverter, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.ComponentModel.TypeConverter, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Timers.Timer member:(null) assembly:/tmp/foo/SwitchPresence-CLI.dll type:Program member:(null)
File name: 'SwitchPresence-CLI'
[ERROR] FATAL UNHANDLED EXCEPTION: System.BadImageFormatException: Could not resolve field token 0x04000005, due to: Could not load type of field 'SwitchPresence_CLI.Program:timer' (0) due to: Could not resolve type with token 0100000d from typeref (expected class 'System.Timers.Timer' in assembly 'System.ComponentModel.TypeConverter, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a') assembly:System.ComponentModel.TypeConverter, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a type:System.Timers.Timer member:(null) assembly:/tmp/foo/SwitchPresence-CLI.dll type:Program member:(null)
File name: 'SwitchPresence-CLI'
gabehxd commented 4 years ago

my bad it should be "dotnet "

ioistired commented 4 years ago
/tmp/tmp.6WE5t5Gao2
➤ dotnet SwitchPresence-CLI.exe
Error:
  An assembly specified in the application dependencies manifest (SwitchPresence-CLI.deps.json) has already been found but with a different file extension:
    package: 'SwitchPresence-CLI', version: '1.0.0'
    path: 'SwitchPresence-CLI.dll'
    previously found assembly: '/tmp/tmp.6WE5t5Gao2/SwitchPresence-CLI.exe'
ioistired commented 4 years ago

oh wait my bad, dotnet SwitchPresence-CLI.dll seems to work

gabehxd commented 4 years ago

uh i think something is wrong on your end try clearing temp?

gabehxd commented 4 years ago

oh ok

gabehxd commented 4 years ago

at it seems it functions i will be closing this issue and merging