Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some features/fixes #6

Merged
merged 10 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CLR_DEV9/CLR_DEV9.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<DependentUpon>ConfigFormIncomingPorts.cs</DependentUpon>
</Compile>
<Compile Include="Config\ConfigHost.cs" />
<Compile Include="Config\ConfigLogging.cs" />
<Compile Include="Config\ConfigIncomingPort.cs" />
<Compile Include="Config\Test\Eth\ARPTest.cs" />
<Compile Include="Config\Test\Eth\DEV9_Test.cs" />
Expand Down
7 changes: 6 additions & 1 deletion CLR_DEV9/Config/ConfigFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PSE;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -31,6 +32,9 @@ class ConfigFile
[DataMember]
public int HddSize;

[DataMember]
public ConfigLogging EnableLogging;

[OnDeserializing]
void OnDeserializing(StreamingContext context)
{
Expand All @@ -47,6 +51,7 @@ private void Init()
HddEnable = false;
DirectConnectionSettings = new ConfigDirectIP();
SocketConnectionSettings = new ConfigSocketIP();
EnableLogging = new ConfigLogging();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do ConfigLogging's defaults apply correctly when loading an older config file (that lacks the entry)?

I remember having issues relating to that in the past.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If config file lacks the entry, it applies default values. (at least on my machine)
However, if you manually add required entries, it still applies default values until you let it recreate config file. (maybe I just did it in wrong order?)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the entries in the file have to be in a specific order for settings to be read. I'm only concerned about updating an old file, and that seems to work.

Hosts = new HashSet<ConfigHost>();
Hosts.Add(new ConfigHost()
{
Expand Down Expand Up @@ -121,7 +126,7 @@ public static void LoadConf(string iniFolderPath, string iniFileName)
if (File.Exists(filePath))
{
DataContractSerializer ConfSerializer = new DataContractSerializer(typeof(ConfigFile));
FileStream Reader = new FileStream(filePath, FileMode.Open);;
FileStream Reader = new FileStream(filePath, FileMode.Open);
DEV9Header.config = (ConfigFile)ConfSerializer.ReadObject(Reader);
Reader.Close();
//Update from old config
Expand Down
30 changes: 30 additions & 0 deletions CLR_DEV9/Config/ConfigLogging.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net;
using System.Runtime.Serialization;

namespace CLRDEV9.Config
{
[DataContract(Namespace = "http://schemas.datacontract.org/2004/07/CLRDEV9")]
class ConfigLogging
{
[DataMember]
public bool Test = true;
[DataMember]
public bool DEV9 = true;
[DataMember]
public bool SPEED = true;
[DataMember]
public bool SMAP = true;
[DataMember]
public bool ATA = true;
[DataMember]
public bool Winsock = true;
[DataMember]
public bool NetAdapter = true;
[DataMember]
public bool UDPSession = true;
[DataMember]
public bool DNSPacket = true;
[DataMember]
public bool DNSSession = true;
}
}
55 changes: 31 additions & 24 deletions CLR_DEV9/DEV9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using PSE;
using PSE.CLR_PSE_Callbacks;
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand All @@ -24,31 +25,44 @@ internal class CLR_DEV9

public static string Name { get { return libraryName; } }

private static void LogInit()
private static void LogSetup()
{
if (doLog)
{
//some legwork to setup the logger
Dictionary<ushort, string> logSources = new Dictionary<ushort, string>();
IEnumerable<DEV9LogSources> sources = Enum.GetValues(typeof(DEV9LogSources)).Cast<DEV9LogSources>();

foreach (DEV9LogSources source in sources)
{
logSources.Add((ushort)source, source.ToString());
}

CLR_PSE_PluginLog.Open(logFolderPath, "DEV9_CLR.log", "CLR_DEV9", logSources);
}
}

private static void LogInit()
{
if (doLog)
{
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.Test, (int)DEV9LogSources.Test);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.DEV9, (int)DEV9LogSources.Dev9);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.SPEED, (int)DEV9LogSources.SPEED);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.SMAP, (int)DEV9LogSources.SMAP);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.ATA, (int)DEV9LogSources.ATA);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.Winsock, (int)DEV9LogSources.Winsock);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.NetAdapter, (int)DEV9LogSources.NetAdapter);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.UDPSession, (int)DEV9LogSources.UDPSession);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.DNSPacket, (int)DEV9LogSources.DNSPacket);
CLR_PSE_PluginLog.SetSourceUseStdOut(DEV9Header.config.EnableLogging.DNSSession, (int)DEV9LogSources.DNSSession);
doLog = false;
}
}

CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.Test);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.Dev9);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.SPEED);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.SMAP);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.ATA);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.Winsock);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.NetAdapter);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.UDPSession);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.DNSPacket);
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.DNSSession);
public static Int32 Init()
{
try
{
LogSetup();
#if DEBUG
CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.PluginInterface);
//CLR_PSE_PluginLog.SetSourceUseStdOut(true, (int)DEV9LogSources.TCPSession);
Expand All @@ -59,14 +73,9 @@ private static void LogInit()
CLR_PSE_PluginLog.SetSourceLogLevel(SourceLevels.All, (int)DEV9LogSources.Dev9);
CLR_PSE_PluginLog.SetSourceLogLevel(SourceLevels.All, (int)DEV9LogSources.SMAP);
#endif
doLog = false;
}
}

public static Int32 Init()
{
try
{
ConfigFile.LoadConf(iniFolderPath, "CLR_DEV9.ini");
Log_Info("Config Loaded");
LogInit();
Log_Info("Init");
dev9 = new DEV9.DEV9_State();
Expand All @@ -86,13 +95,11 @@ public static Int32 Open(IntPtr winHandle)
int ret = 0;

Log_Info("Open");
ConfigFile.LoadConf(iniFolderPath, "CLR_DEV9.ini");
Log_Info("Config Loaded");

if (DEV9Header.config.Hdd.Contains("\\") || DEV9Header.config.Hdd.Contains("/"))
if (DEV9Header.config.Hdd.Contains(Path.DirectorySeparatorChar))
ret = dev9.Open(DEV9Header.config.Hdd);
else
ret = dev9.Open(iniFolderPath + "\\" + DEV9Header.config.Hdd);
ret = dev9.Open(iniFolderPath + Path.DirectorySeparatorChar + DEV9Header.config.Hdd);

if (ret == 0)
Log_Info("Open ok");
Expand Down
4 changes: 3 additions & 1 deletion CLR_DEV9/PSE/CLR_PSE_PluginLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public static void Close()

public static void WriteLine(TraceEventType eType, int logSource, string str)
{
if (sources == null) return;
if (sources == null)
return;
if (sources.ContainsKey(logSource))
{
sources[logSource].TraceEvent(eType, logSource, str);
Expand All @@ -189,6 +190,7 @@ public static void MsgBoxErrorTrapper(Exception e)
{
Console.Error.WriteLine(e.Message + Environment.NewLine + e.StackTrace);
#if NETCOREAPP2_0
SDL2.MessageBox.Show(SDL2.MessageBoxFlags.Error, "Fatal Error", "Encounted Exception! : " + e.Message + Environment.NewLine + e.StackTrace);
#else
System.Windows.Forms.MessageBox.Show("Encounted Exception! : " + e.Message + Environment.NewLine + e.StackTrace);
#endif
Expand Down
26 changes: 26 additions & 0 deletions CLR_DEV9/PSE/CoreCLR/SDL2MessageBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace SDL2
{
enum MessageBoxFlags
{
Error = 0x00000010,
Warning = 0x00000020,
Information = 0x00000040
}

static class MessageBox
{
[DllImport("SDL2")]
private static extern int SDL_ShowSimpleMessageBox(uint flags, string title, string message, IntPtr window);

public static int Show(MessageBoxFlags flags, string title, string message)
{
return SDL_ShowSimpleMessageBox((uint)flags, title, message, new IntPtr(0));
}
}
}
18 changes: 18 additions & 0 deletions CLR_DEV9_LINUX/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.10)
project(clrdev9)

add_library(${PROJECT_NAME} SHARED
coreclrhost.h
DEV9.h
DEV9.cpp
PSE.h
PSE.cpp
)

set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
target_link_libraries(${PROJECT_NAME}
m
rt
dl
pthread
)
2 changes: 2 additions & 0 deletions CLR_DEV9_LINUX/DEV9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ string pluginPSEType = "PSE.CLR_PSE_DEV9";

string configDir;
string logDir;
string PCSX2HomeDir;

//MonoDomain *pluginDomain = NULL;
//MonoAssembly *pluginAssembly = NULL;
Expand Down Expand Up @@ -171,6 +172,7 @@ DEV9setSettingsDir(const char* dir)
PSELog.Write("SetSetting\n");

configDir = dir;
PCSX2HomeDir = configDir.substr(0, configDir.substr(0, configDir.length()-1).find_last_of("/"));
//string configPath = configDir + configFileName;

//ifstream reader;
Expand Down
3 changes: 1 addition & 2 deletions CLR_DEV9_LINUX/PSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ void LoadCoreCLR(string pluginPath, string coreClrFolder)

if (coreClrFolder.length() == 0)
{
//coreClrFolder = "/home/air/git/ReadyBin.Release";
coreClrFolder = "/home/air/git/ReadyBin.Debug";
coreClrFolder = PCSX2HomeDir + "/coreclr";
}

string coreClrPath = coreClrFolder + "/" + "libcoreclr.so";
Expand Down
1 change: 1 addition & 0 deletions CLR_DEV9_LINUX/PSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern const uint32_t pluginType;
extern const uint8_t pluginVerMajor;
extern const uint8_t pluginVerMinor;
extern const uint8_t pluginVerPatch;
extern std::string PCSX2HomeDir;

//helper methods
extern coreclr_create_delegate_ptr createDelegate;
Expand Down