Skip to content

Commit

Permalink
Moved client and server version checks to settings file.
Browse files Browse the repository at this point in the history
Cleaned up use of settings in setup program
  • Loading branch information
Chicken-Bones committed Oct 8, 2016
1 parent e1a123f commit 479bdf4
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 87 deletions.
18 changes: 18 additions & 0 deletions setup/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions setup/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@
<Setting Name="tModLoaderDiffCutoff" Type="System.DateTime" Scope="User">
<Value Profile="(Default)">2015-01-01</Value>
</Setting>
<Setting Name="ClientVersion" Type="System.String" Scope="Application">
<Value Profile="(Default)">1.3.3.1</Value>
</Setting>
<Setting Name="ServerVersion" Type="System.String" Scope="Application">
<Value Profile="(Default)">1.3.3.2</Value>
</Setting>
</Settings>
</SettingsFile>
24 changes: 10 additions & 14 deletions setup/Setup/DecompileTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.TextView;
using Mono.Cecil;
using static Terraria.ModLoader.Setup.Settings;
using Terraria.ModLoader.Properties;
using static Terraria.ModLoader.Setup.Program;

namespace Terraria.ModLoader.Setup
{
Expand Down Expand Up @@ -54,8 +55,8 @@ public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderPar
private static readonly CSharpLanguage lang = new CSharpLanguage();
private static readonly Guid clientGuid = new Guid("3996D5FA-6E59-4FE4-9F2B-40EEEF9645D5");
private static readonly Guid serverGuid = new Guid("85BF1171-A0DC-4696-BFA4-D6E9DC4E0830");
public static readonly Version version = new Version(1, 3, 3, 1);
public static readonly Version versionAlt = new Version(1, 3, 3, 2); // For some reason, this update, only the server has an updated version.
public static readonly Version clientVersion = new Version(Settings.Default.ClientVersion);
public static readonly Version serverVersion = new Version(Settings.Default.ServerVersion);

public string srcDir;
private ModuleDefinition clientModule;
Expand Down Expand Up @@ -100,8 +101,8 @@ public override void Run() {

resolver.baseModule = clientModule;

VersionCheck(clientModule.Assembly);
VersionCheckAlt(serverModule.Assembly);
VersionCheck(clientModule.Assembly, clientVersion);
VersionCheck(serverModule.Assembly, serverVersion);

var options = new DecompilationOptions {
FullDecompilation = true,
Expand Down Expand Up @@ -135,24 +136,19 @@ public override void Run() {
() => WriteProjectFile(serverModule, serverGuid, serverSources, serverResources, options)));

items.Add(new WorkItem("Writing Terraria"+lang.ProjectFileExtension+".user",
() => WriteProjectUserFile(clientModule, SteamDir.Get(), options)));
() => WriteProjectUserFile(clientModule, SteamDir, options)));

items.Add(new WorkItem("Writing TerrariaServer"+lang.ProjectFileExtension+".user",
() => WriteProjectUserFile(serverModule, SteamDir.Get(), options)));
() => WriteProjectUserFile(serverModule, SteamDir, options)));

ExecuteParallel(items, maxDegree: SingleDecompileThread.Get() ? 1 : 0);
ExecuteParallel(items, maxDegree: Settings.Default.SingleDecompileThread ? 1 : 0);
}

private void VersionCheck(AssemblyDefinition assembly) {
private void VersionCheck(AssemblyDefinition assembly, Version version) {
if (assembly.Name.Version != version)
throw new Exception($"{assembly.Name.Name} version {assembly.Name.Version}. Expected {version}");
}

private void VersionCheckAlt(AssemblyDefinition assembly) {
if (assembly.Name.Version != versionAlt)
throw new Exception($"{assembly.Name.Name} version {assembly.Name.Version}. Expected {versionAlt}");
}

#region ReflectedMethods
private static readonly MethodInfo _IncludeTypeWhenDecompilingProject = typeof(CSharpLanguage)
.GetMethod("IncludeTypeWhenDecompilingProject", BindingFlags.NonPublic | BindingFlags.Instance);
Expand Down
36 changes: 20 additions & 16 deletions setup/Setup/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using static Terraria.ModLoader.Setup.Settings;
using Terraria.ModLoader.Properties;
using static Terraria.ModLoader.Setup.Program;

namespace Terraria.ModLoader.Setup
{
Expand All @@ -20,12 +21,12 @@ public MainForm()
InitializeComponent();

taskButtons[buttonDecompile] = () => new DecompileTask(this, "src/decompiled");
taskButtons[buttonDiffMerged] = () => new DiffTask(this, "src/decompiled", "src/merged", "patches/merged", MergedDiffCutoff);
taskButtons[buttonPatchMerged] = () => new PatchTask(this, "src/decompiled", "src/merged", "patches/merged", MergedDiffCutoff);
taskButtons[buttonDiffTerraria] = () => new DiffTask(this, "src/merged", "src/Terraria", "patches/Terraria", TerrariaDiffCutoff);
taskButtons[buttonPatchTerraria] = () => new PatchTask(this, "src/merged", "src/Terraria", "patches/Terraria", TerrariaDiffCutoff);
taskButtons[buttonDiffModLoader] = () => new DiffTask(this, "src/Terraria", "src/tModLoader", "patches/tModLoader", tModLoaderDiffCutoff, FormatTask.tModLoaderFormat);
taskButtons[buttonPatchModLoader] = () => new PatchTask(this, "src/Terraria", "src/tModLoader", "patches/tModLoader", tModLoaderDiffCutoff, FormatTask.tModLoaderFormat);
taskButtons[buttonDiffMerged] = () => new DiffTask(this, "src/decompiled", "src/merged", "patches/merged", new ProgramSetting<DateTime>("MergedDiffCutoff"));
taskButtons[buttonPatchMerged] = () => new PatchTask(this, "src/decompiled", "src/merged", "patches/merged", new ProgramSetting<DateTime>("MergedDiffCutoff"));
taskButtons[buttonDiffTerraria] = () => new DiffTask(this, "src/merged", "src/Terraria", "patches/Terraria", new ProgramSetting<DateTime>("TerrariaDiffCutoff"));
taskButtons[buttonPatchTerraria] = () => new PatchTask(this, "src/merged", "src/Terraria", "patches/Terraria", new ProgramSetting<DateTime>("TerrariaDiffCutoff"));
taskButtons[buttonDiffModLoader] = () => new DiffTask(this, "src/Terraria", "src/tModLoader", "patches/tModLoader", new ProgramSetting<DateTime>("tModLoaderDiffCutoff"), FormatTask.tModLoaderFormat);
taskButtons[buttonPatchModLoader] = () => new PatchTask(this, "src/Terraria", "src/tModLoader", "patches/tModLoader", new ProgramSetting<DateTime>("tModLoaderDiffCutoff"), FormatTask.tModLoaderFormat);
taskButtons[buttonSetupDebugging] = () => new SetupDebugTask(this);
taskButtons[buttonFormat] = () => new FormatTask(this, FormatTask.tModLoaderFormat);

Expand All @@ -37,8 +38,8 @@ public MainForm()
new SetupTask(this, new[] { buttonDecompile, buttonPatchMerged, buttonPatchTerraria, buttonPatchModLoader, buttonSetupDebugging }
.Select(b => taskButtons[b]()).ToArray());

menuItemWarnings.Checked = Program.SuppressWarnings.Get();
menuItemSingleDecompileThread.Checked = SingleDecompileThread.Get();
menuItemWarnings.Checked = Settings.Default.SuppressWarnings;
menuItemSingleDecompileThread.Checked = Settings.Default.SingleDecompileThread;

Closing += (sender, args) =>
{
Expand Down Expand Up @@ -92,19 +93,22 @@ private void menuItemTerraria_Click(object sender, EventArgs e)

private void menuItemWarnings_Click(object sender, EventArgs e)
{
Program.SuppressWarnings.Set(menuItemWarnings.Checked);
Settings.Default.SuppressWarnings = menuItemWarnings.Checked;
Settings.Default.Save();
}

private void menuItemSingleDecompileThread_Click(object sender, EventArgs e)
{
SingleDecompileThread.Set(menuItemSingleDecompileThread.Checked);
Settings.Default.SingleDecompileThread = menuItemSingleDecompileThread.Checked;
Settings.Default.Save();
}

private void menuItemResetTimeStampOptmizations_Click(object sender, EventArgs e)
{
MergedDiffCutoff.Set(new DateTime(2015, 1, 1));
TerrariaDiffCutoff.Set(new DateTime(2015, 1, 1));
tModLoaderDiffCutoff.Set(new DateTime(2015, 1, 1));
Settings.Default.MergedDiffCutoff = new DateTime(2015, 1, 1);
Settings.Default.TerrariaDiffCutoff = new DateTime(2015, 1, 1);
Settings.Default.tModLoaderDiffCutoff = new DateTime(2015, 1, 1);
Settings.Default.Save();
}

private void buttonTask_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -132,7 +136,7 @@ private void RunTaskThread(Task task)
if (!task.ConfigurationDialog())
return;

if (!Program.SuppressWarnings.Get() && !task.StartupWarning())
if (!Settings.Default.SuppressWarnings && !task.StartupWarning())
return;

try
Expand All @@ -153,7 +157,7 @@ private void RunTaskThread(Task task)
return;
}

if ((task.Failed() || task.Warnings() && !Program.SuppressWarnings.Get()))
if ((task.Failed() || task.Warnings() && !Settings.Default.SuppressWarnings))
task.FinishedDialog();

Invoke(new Action(() =>
Expand Down
37 changes: 35 additions & 2 deletions setup/Setup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Terraria.ModLoader.Properties;

namespace Terraria.ModLoader.Setup
{
Expand All @@ -16,7 +17,10 @@ static class Program
public static readonly string libDir = Path.Combine(appDir, "..", "lib");
public static readonly string toolsDir = Path.Combine(appDir, "..", "tools");
public static string LogDir => Path.Combine(baseDir, "logs");
public static ProgramSetting<bool> SuppressWarnings = new ProgramSetting<bool>("SuppressWarnings");

public static string SteamDir => Settings.Default.SteamDir;
public static string TerrariaPath => Path.Combine(SteamDir, "Terraria.exe");
public static string TerrariaServerPath => Path.Combine(SteamDir, "TerrariaServer.exe");

/// <summary>
/// The main entry point for the application.
Expand All @@ -33,7 +37,7 @@ static void Main(string[] args) {
};

if (args.Length == 1 && args[0] == "--steamdir") {
Console.WriteLine(Settings.SteamDir.Get());
Console.WriteLine(SteamDir);
return;
}

Expand Down Expand Up @@ -109,6 +113,35 @@ public static int RunCmd(string dir, string cmd, string args,

return process.ExitCode;
}
}

public static bool SelectTerrariaDialog() {
while (true) {
var dialog = new OpenFileDialog {
InitialDirectory = Path.GetFullPath(Directory.Exists(SteamDir) ? SteamDir : baseDir),
Filter = "Terraria|Terraria.exe",
Title = "Select Terraria.exe"
};

if (dialog.ShowDialog() != DialogResult.OK)
return false;

string err = null;
if (Path.GetFileName(dialog.FileName) != "Terraria.exe")
err = "File must be named Terraria.exe";
else if (!File.Exists(Path.Combine(Path.GetDirectoryName(dialog.FileName), "TerrariaServer.exe")))
err = "TerrariaServer.exe does not exist in the same directory";

if (err != null) {
if (MessageBox.Show(err, "Invalid Selection", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Cancel)
return false;
}
else {
Settings.Default.SteamDir = Path.GetDirectoryName(dialog.FileName);
Settings.Default.Save();
return true;
}
}
}
}
}
10 changes: 6 additions & 4 deletions setup/Setup/ProgramSetting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Terraria.ModLoader.Setup
using Terraria.ModLoader.Properties;

namespace Terraria.ModLoader.Setup
{
public class ProgramSetting<T>
{
Expand All @@ -9,12 +11,12 @@ public ProgramSetting(string key) {
}

public void Set(T value) {
Properties.Settings.Default[key] = value;
Properties.Settings.Default.Save();
Settings.Default[key] = value;
Settings.Default.Save();
}

public T Get() {
return (T)Properties.Settings.Default[key];
return (T)Settings.Default[key];
}
}
}
47 changes: 0 additions & 47 deletions setup/Setup/Settings.cs

This file was deleted.

6 changes: 3 additions & 3 deletions setup/Setup/SetupDebugTask.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using System.Windows.Forms;
using static Terraria.ModLoader.Setup.Settings;
using static Terraria.ModLoader.Setup.Program;

namespace Terraria.ModLoader.Setup
{
Expand All @@ -21,7 +21,7 @@ public override bool ConfigurationDialog() {
public override void Run() {
taskInterface.SetStatus("Copying References");

var modCompile = Path.Combine(SteamDir.Get(), "ModCompile");
var modCompile = Path.Combine(SteamDir, "ModCompile");

var references = new[] {"FNA.dll", "Microsoft.CodeAnalysis.dll", "Microsoft.CodeAnalysis.CSharp.dll",
"System.Reflection.Metadata.dll", "Mono.Cecil.Pdb.dll" };
Expand Down Expand Up @@ -62,6 +62,6 @@ public override void FinishedDialog() {
<StartProgram>%steamdir%\tModLoaderServerDebug.exe</StartProgram>
<StartWorkingDirectory>%steamdir%</StartWorkingDirectory>
</PropertyGroup>
</Project>".Replace("%steamdir%", SteamDir.Get());
</Project>".Replace("%steamdir%", SteamDir);
}
}
13 changes: 13 additions & 0 deletions setup/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Terraria.ModLoader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Terraria.ModLoader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<Terraria.ModLoader.Properties.Settings>
Expand All @@ -27,4 +30,14 @@
</setting>
</Terraria.ModLoader.Properties.Settings>
</userSettings>
<applicationSettings>
<Terraria.ModLoader.Properties.Settings>
<setting name="ClientVersion" serializeAs="String">
<value>1.3.3.1</value>
</setting>
<setting name="ServerVersion" serializeAs="String">
<value>1.3.3.2</value>
</setting>
</Terraria.ModLoader.Properties.Settings>
</applicationSettings>
</configuration>
Binary file modified setup/bin/setup.exe
Binary file not shown.
13 changes: 13 additions & 0 deletions setup/bin/setup.exe.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Terraria.ModLoader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Terraria.ModLoader.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<Terraria.ModLoader.Properties.Settings>
Expand All @@ -27,4 +30,14 @@
</setting>
</Terraria.ModLoader.Properties.Settings>
</userSettings>
<applicationSettings>
<Terraria.ModLoader.Properties.Settings>
<setting name="ClientVersion" serializeAs="String">
<value>1.3.3.1</value>
</setting>
<setting name="ServerVersion" serializeAs="String">
<value>1.3.3.2</value>
</setting>
</Terraria.ModLoader.Properties.Settings>
</applicationSettings>
</configuration>
Binary file modified setup/bin/setup.pdb
Binary file not shown.
Loading

0 comments on commit 479bdf4

Please sign in to comment.