Skip to content

Commit

Permalink
remove obsolete console stuff, new logging project (#238)
Browse files Browse the repository at this point in the history
* removed obsolete console stuff
* migrated logging stuff to new project
* static console for OWML
  • Loading branch information
amazingalek authored Jul 30, 2020
1 parent e998e67 commit d6796a8
Show file tree
Hide file tree
Showing 47 changed files with 259 additions and 151 deletions.
1 change: 1 addition & 0 deletions OWML.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class Constants
{
public const string OwmlTitle = "OWML";
public const string ConsolePortArgument = "consolePort";
public const string OwmlConfigFileName = "OWML.Config.json";
public const string OwmlDefaultConfigFileName = "OWML.DefaultConfig.json";
Expand Down
4 changes: 4 additions & 0 deletions OWML.Launcher/OWML.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
<Project>{a3d507f5-22a2-4a18-b529-868fe8d59cf3}</Project>
<Name>OWML.GameFinder</Name>
</ProjectReference>
<ProjectReference Include="..\OWML.Logging\OWML.Logging.csproj">
<Project>{6F14D39C-5747-4149-BE4D-365B43918A0A}</Project>
<Name>OWML.Logging</Name>
</ProjectReference>
<ProjectReference Include="..\OWML.ModHelper\OWML.ModHelper.csproj">
<Project>{CB57BAB8-D70E-4FCE-9BF1-328A924173A7}</Project>
<Name>OWML.ModHelper</Name>
Expand Down
1 change: 1 addition & 0 deletions OWML.Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using OWML.Common;
using OWML.GameFinder;
using OWML.Logging;
using OWML.ModHelper;
using OWML.ModLoader;
using OWML.Patcher;
Expand Down
1 change: 1 addition & 0 deletions OWML.Launcher/SocketListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using OWML.Logging;

namespace OWML.Launcher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using OWML.Common;
using System;
using System;
using System.Collections.Generic;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public static class ConsoleUtils
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public abstract class ModConsole : IModConsole
{
[Obsolete("Use ModHelper.Console instead")]
public static ModConsole Instance { get; private set; }

public static event Action<IModManifest, string> OnConsole;
public static ModConsole OwmlConsole { get; private set; }

protected readonly IModLogger Logger;
protected readonly IModManifest Manifest;
Expand All @@ -26,15 +23,10 @@ protected ModConsole(IOwmlConfig config, IModLogger logger, IModManifest manifes
Manifest = manifest;
OwmlConfig = config;

if (manifest.Name == "OWML")
if (Manifest.Name == Constants.OwmlTitle)
{
Instance = this;
OwmlConsole = this;
}
}

internal static void CallWriteCallback(IModManifest manifest, string text)
{
OnConsole?.Invoke(manifest, text);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,16 @@
using System.Linq;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public class ModLogger : IModLogger
{
[Obsolete("Use ModHelper.Logger instead")]
public static ModLogger Instance { get; private set; }

public static event Action<IModManifest, string> OnLog;


private static IOwmlConfig _config;
private readonly IModManifest _manifest;
private static string _logFileName;

public ModLogger(IOwmlConfig config, IModManifest manifest, string logFileName)
{
if (manifest.Name == "OWML")
{
Instance = this;
}
if (_config == null)
{
_config = config;
Expand All @@ -33,7 +23,6 @@ public ModLogger(IOwmlConfig config, IModManifest manifest, string logFileName)

public void Log(string s)
{
OnLog?.Invoke(_manifest, s);
var message = $"[{_manifest.Name}]: {s}";
LogInternal(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Newtonsoft.Json;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public class ModSocket : IModSocket
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Newtonsoft.Json;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public class ModSocketMessage : IModSocketMessage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public class ModSocketOutput : ModConsole
{
Expand Down Expand Up @@ -35,7 +35,6 @@ public override void WriteLine(string line, MessageType type)
private void WriteLine(MessageType type, string line, string senderType)
{
Logger?.Log(line);
CallWriteCallback(Manifest, line);

var message = new ModSocketMessage
{
Expand All @@ -57,8 +56,8 @@ private string GetCallingType(StackTrace frame)
{
var message = new ModSocketMessage
{
SenderName = "OWML",
SenderType = "ModSocketOutput",
SenderName = Constants.OwmlTitle,
SenderType = nameof(ModSocketOutput),
Type = MessageType.Error,
Message = $"Error while getting calling type : {ex.Message}"
};
Expand Down
98 changes: 98 additions & 0 deletions OWML.Logging/OWML.Logging.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6F14D39C-5747-4149-BE4D-365B43918A0A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OWML.Logging</RootNamespace>
<AssemblyName>OWML.Logging</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OW.Unity.Dlls, Version=1.0.7.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\OW.Unity.Dlls.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AudioModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.AudioModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.UIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestWWWModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OW.Unity.Dlls.1.0.7\lib\net35\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleUtils.cs" />
<Compile Include="ModConsole.cs" />
<Compile Include="ModLogger.cs" />
<Compile Include="ModSocket.cs" />
<Compile Include="ModSocketMessage.cs" />
<Compile Include="ModSocketOutput.cs" />
<Compile Include="OutputWriter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnityLogger.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OWML.Common\OWML.Common.csproj">
<Project>{3C00626F-B688-4F32-B493-5B7EC1C879A0}</Project>
<Name>OWML.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using OWML.Common;

namespace OWML.ModHelper
namespace OWML.Logging
{
public class OutputWriter : IModConsole
{
Expand Down
35 changes: 35 additions & 0 deletions OWML.Logging/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OWML.Logger")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OWML.Logger")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6f14d39c-5747-4149-be4d-365b43918a0a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using OWML.Common;
using UnityEngine;

namespace OWML.ModHelper
namespace OWML.Logging
{
public class UnityLogger
{
Expand Down
5 changes: 5 additions & 0 deletions OWML.Logging/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Json.Net.Unity3D" version="9.0.1" targetFramework="net35" />
<package id="OW.Unity.Dlls" version="1.0.7" targetFramework="net35" />
</packages>
3 changes: 1 addition & 2 deletions OWML.ModHelper.Menus/ModConfigMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public class ModConfigMenu : ModConfigMenuBase, IModConfigMenu
public IModData ModData { get; }
public IModBehaviour Mod { get; }

public ModConfigMenu(IModConsole console, IModData modData, IModBehaviour mod)
: base(console, modData.Manifest)
public ModConfigMenu(IModData modData, IModBehaviour mod) : base(modData.Manifest)
{
ModData = modData;
Mod = mod;
Expand Down
7 changes: 4 additions & 3 deletions OWML.ModHelper.Menus/ModConfigMenuBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OWML.Common;
using OWML.Common.Menus;
using System.Linq;
using OWML.Logging;

namespace OWML.ModHelper.Menus
{
Expand All @@ -21,7 +22,7 @@ public abstract class ModConfigMenuBase : ModMenuWithSelectables, IModConfigMenu
protected abstract void AddInputs();
protected abstract void UpdateUIValues();

protected ModConfigMenuBase(IModConsole console, IModManifest manifest) : base(console)
protected ModConfigMenuBase(IModManifest manifest)
{
Manifest = manifest;
Storage = new ModStorage(manifest);
Expand Down Expand Up @@ -88,12 +89,12 @@ protected void AddConfigInput(string key, object value, int index)
AddComboInput(key, index);
return;
default:
OwmlConsole.WriteLine("Error - Unrecognized complex setting: " + value, MessageType.Error);
ModConsole.OwmlConsole.WriteLine("Error - Unrecognized complex setting: " + value, MessageType.Error);
return;
}
}

OwmlConsole.WriteLine("Error - Unrecognized setting type: " + value.GetType(), MessageType.Error);
ModConsole.OwmlConsole.WriteLine("Error - Unrecognized setting type: " + value.GetType(), MessageType.Error);
}

private void AddToggleInput(string key, int index)
Expand Down
3 changes: 2 additions & 1 deletion OWML.ModHelper.Menus/ModInputCombinationElement.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using OWML.Common;
using OWML.Common.Menus;
using OWML.Logging;
using OWML.ModHelper.Input;
using UnityEngine;
using UnityEngine.UI;
Expand Down Expand Up @@ -45,7 +46,7 @@ public ModInputCombinationElement(TwoButtonToggleElement toggle, IModMenu menu,
.GetComponentInChildren<HorizontalLayoutGroup>(true).gameObject;
if (layoutObject == null)
{
ModConsole.Instance.WriteLine("Error - Failed to setup an element for combination editor.", MessageType.Error);
ModConsole.OwmlConsole.WriteLine("Error - Failed to setup an element for combination editor.", MessageType.Error);
return;
}
var layoutGroup = layoutObject.GetComponent<HorizontalLayoutGroup>();
Expand Down
Loading

0 comments on commit d6796a8

Please sign in to comment.