Skip to content

Commit

Permalink
Merge pull request #14 from AxeelAnder/master
Browse files Browse the repository at this point in the history
v1.1.1.6
  • Loading branch information
AxeelAnder authored Nov 9, 2019
2 parents d9d9921 + 0c4a181 commit 9c54b20
Show file tree
Hide file tree
Showing 124 changed files with 2,168 additions and 1,110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
run: '& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" Localizer.sln /p:Configuration=Release /p:Platform=x86'

- name: Run Tests
run: '& ".\packages\xunit.runner.console.2.4.1\tools\net472\xunit.console.x86.exe" ".\LocalizerTest\bin\x86\Release\LocalizerTest.dll"'
run: '& ".\packages\xunit.runner.console.2.4.1\tools\net472\xunit.console.x86.exe" ".\LocalizerTest\bin\Release\LocalizerTest.dll"'
9 changes: 2 additions & 7 deletions Launcher/Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<Import Project="..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props" Condition="Exists('..\packages\xunit.runner.console.2.4.1\build\xunit.runner.console.props')" />
<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>{047C62F2-9E0F-4560-9923-DC5D0FE28B7F}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Launcher</RootNamespace>
Expand All @@ -22,7 +20,7 @@
<DefineConstants>DEBUG;TRACE;LAUNCHER</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>bin\x86\Debug\</OutputPath>
<OutputPath>bin\Debug\</OutputPath>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
Expand All @@ -31,7 +29,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<OutputPath>bin\x86\Release\</OutputPath>
<OutputPath>bin\Release\</OutputPath>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
Expand All @@ -43,9 +41,6 @@
<HintPath>..\Localizer\Plugins\LocalizerWPF.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="ReLogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\References\ModCompile\ReLogic.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
21 changes: 7 additions & 14 deletions Launcher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Localizer;
using LocalizerWPF;
using Terraria.ModLoader;

namespace Launcher
{
internal class Program
public class Program
{
[STAThread]
private static void Main(string[] args)
{
#if DEBUG
GenBuildPath();
#endif
try
{
var localizer = new Localizer.Localizer();
localizer.Load();

var app = new App();
app.InitializeComponent();
app.Run();
Expand All @@ -26,14 +28,5 @@ private static void Main(string[] args)
Console.WriteLine(e);
}
}

// For reading modules from solution directory, need a better and more elegant approach to implement this.
private static void GenBuildPath()
{
var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"localizer_build_path");

File.WriteAllText(filePath, Path.GetFullPath("../../../../Localizer/Plugins/"));
}
}
}
6 changes: 0 additions & 6 deletions Localizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModBrowserMirror", "ModBrow
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
Expand All @@ -27,12 +25,8 @@ Global
{95D54B28-B67B-4248-B83A-B5E5426C3806}.Release|Any CPU.ActiveCfg = Release|x86
{95D54B28-B67B-4248-B83A-B5E5426C3806}.Release|x86.ActiveCfg = Release|x86
{95D54B28-B67B-4248-B83A-B5E5426C3806}.Release|x86.Build.0 = Release|x86
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Debug|x86.ActiveCfg = Debug|x86
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Debug|x86.Build.0 = Debug|x86
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Release|Any CPU.Build.0 = Release|Any CPU
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Release|x86.ActiveCfg = Release|x86
{CFBF9137-ECC6-4771-96E2-F7C93C40F085}.Release|x86.Build.0 = Release|x86
{047C62F2-9E0F-4560-9923-DC5D0FE28B7F}.Debug|Any CPU.ActiveCfg = Debug|x86
Expand Down
3 changes: 2 additions & 1 deletion Localizer.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=TestWPF_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=TestWPF_002EAnnotations/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Localizer/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
14 changes: 14 additions & 0 deletions Localizer/Attributes/OperationTimingAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Localizer.Attributes
{
public class OperationTimingAttribute : Attribute
{
public OperationTiming Timing { get; }

public OperationTimingAttribute(OperationTiming timing = OperationTiming.Any)
{
Timing = timing;
}
}
}
8 changes: 8 additions & 0 deletions Localizer/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ public class Configuration
{
public bool AutoImport { get; set; } = true;

public AutoImportType AutoImportType { get; set; } = AutoImportType.All;

public bool ShowUI { get; set; } = true;

public LogLevel LogLevel { get; set; } = LogLevel.Info;

public bool RebuildTooltips { get; set; } = true;

public bool RebuildTooltipsOnce { get; set; } = true;
}
}
2 changes: 2 additions & 0 deletions Localizer/DataModel/Default/LdstrFile.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Localizer.Attributes;

namespace Localizer.DataModel.Default
{
Expand All @@ -20,6 +21,7 @@ public IEntry Clone()
}
}

[OperationTiming]
public class LdstrFile : IFile
{
public Dictionary<string, LdstrEntry> LdstrEntries { get; set; } = new Dictionary<string, LdstrEntry>();
Expand Down
49 changes: 49 additions & 0 deletions Localizer/DataModel/Default/LoadedModWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Reflection;
using Localizer.Helpers;
using Terraria;
using Terraria.ModLoader;
using Terraria.ModLoader.Core;

namespace Localizer.DataModel.Default
{
public class LoadedModWrapper : IMod
{
private readonly WeakReference<object> wrapped;

public LoadedModWrapper(object mod)
{
wrapped = new WeakReference<object>(mod);
name = mod.Prop("Name") as string;
if (name == "ModLoader")
{
code = Assembly.GetAssembly(typeof(Main));
}
else
{
code = mod.Field("assembly") as Assembly;
}
var buildProp = mod.Field("properties");
displayName = buildProp.Field("displayName") as string;
version = buildProp.Field("version") as Version;
file = mod.Field("modFile") as TmodFile;
}

public string Name => name ?? "";
private string name;

public Assembly Code => code;
private Assembly code;

public string DisplayName => displayName ?? "";
private string displayName;

public Version Version => version ?? new Version();
private Version version;

public TmodFile File => file;
private TmodFile file;

public bool Enabled => (bool)typeof(ModLoader).Method("IsEnabled", Name);
}
}
24 changes: 23 additions & 1 deletion Localizer/DataModel/Default/ModWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Reflection;
using Localizer.Helpers;
using Terraria;
using Terraria.ModLoader;
using Terraria.ModLoader.Core;

namespace Localizer.DataModel.Default
{
Expand All @@ -10,6 +13,8 @@ public class ModWrapper : IMod

public ModWrapper(Mod mod)
{
if(mod is null)
throw new ArgumentNullException(nameof(mod));
wrapped = new WeakReference<Mod>(mod);
}

Expand All @@ -25,8 +30,25 @@ public Mod Mod

public string Name => Mod?.Name ?? "";

public Assembly Code => Mod?.Code;
public Assembly Code
{
get
{

if (Name == "ModLoader")
{
return Assembly.GetAssembly(typeof(Main));
}
else
{
return Mod?.Code;
}
}
}

public string DisplayName => Mod.DisplayName ?? "";
public Version Version => Mod?.Version;
public TmodFile File => Mod?.Prop("File") as TmodFile;
public bool Enabled => (bool)typeof(ModLoader).Method("IsEnabled", Name);
}
}
8 changes: 8 additions & 0 deletions Localizer/DataModel/IMod.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Reflection;
using Terraria.ModLoader.Core;

namespace Localizer.DataModel
{
Expand All @@ -24,5 +25,12 @@ public interface IMod
/// Version of the mod.
/// </summary>
Version Version { get; }

/// <summary>
/// File of the mod.
/// </summary>
TmodFile File { get; }

bool Enabled { get; }
}
}
39 changes: 39 additions & 0 deletions Localizer/Disposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace Localizer
{
public abstract class Disposable : IDisposable
{
protected bool disposed = false;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

~Disposable()
{
Dispose(false);
}

protected virtual void Dispose(bool disposeManaged)
{
if (!disposed)
{
if (disposeManaged)
{
DisposeManaged();
}

DisposeUnmanaged();

disposed = true;
}
}

protected virtual void DisposeManaged() { }

protected virtual void DisposeUnmanaged() { }
}
}
13 changes: 13 additions & 0 deletions Localizer/Enums/AutoImportType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Localizer
{
[JsonConverter(typeof(StringEnumConverter))]
public enum AutoImportType
{
All,
DownloadedOnly,
SourceOnly,
}
}
15 changes: 15 additions & 0 deletions Localizer/Enums/LogLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Localizer
{
[JsonConverter(typeof(StringEnumConverter))]
public enum LogLevel : byte
{
Fatal = 0,
Error = 1,
Warn = 2,
Info = 3,
Debug = 4,
}
}
14 changes: 14 additions & 0 deletions Localizer/Enums/OperationTiming.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Localizer
{
[Flags]
public enum OperationTiming : byte
{
BeforeModCtor = 0b00000001,
BeforeModLoad = 0b00000010,
BeforeContentLoad = 0b00000100,
PostContentLoad = 0b00001000,
Any = 0b11111111,
}
}
8 changes: 8 additions & 0 deletions Localizer/Enums/PackageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Localizer
{
public enum PackageType
{
Packed,
Source,
}
}
Loading

0 comments on commit 9c54b20

Please sign in to comment.