Use file scoped namespaces

pull/5/head
Miepee 4 years ago
parent 2a08ff2946
commit 9ad9935fff

@ -1,9 +1,6 @@
using System;
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Parsing;
using System.IO;
using System.Threading;
using AM2RPortHelperLib;
namespace AM2RPortHelper;

@ -1,14 +1,13 @@
using System;
using Eto.Forms;
namespace AM2RPortHelperGUI.Gtk
namespace AM2RPortHelperGUI.Gtk;
class Program
{
class Program
[STAThread]
public static void Main(string[] args)
{
[STAThread]
public static void Main(string[] args)
{
new Application(Eto.Platforms.Gtk).Run(new MainForm());
}
new Application(Eto.Platforms.Gtk).Run(new MainForm());
}
}
}

@ -1,14 +1,13 @@
using System;
using Eto.Forms;
namespace AM2RPortHelperGUI.Mac
namespace AM2RPortHelperGUI.Mac;
class Program
{
class Program
[STAThread]
public static void Main(string[] args)
{
[STAThread]
public static void Main(string[] args)
{
new Application(Eto.Platforms.Mac64).Run(new MainForm());
}
new Application(Eto.Platforms.Mac64).Run(new MainForm());
}
}
}

@ -1,14 +1,13 @@
using System;
using Eto.Forms;
namespace AM2RPortHelperGUI.Wpf
namespace AM2RPortHelperGUI.Wpf;
class Program
{
class Program
[STAThread]
public static void Main(string[] args)
{
[STAThread]
public static void Main(string[] args)
{
new Application(Eto.Platforms.Wpf).Run(new MainForm());
}
new Application(Eto.Platforms.Wpf).Run(new MainForm());
}
}
}

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>

@ -7,165 +7,164 @@ using AM2RPortHelperLib;
using Eto.Forms;
using Eto.Drawing;
namespace AM2RPortHelperGUI
namespace AM2RPortHelperGUI;
public partial class MainForm : Form
{
public partial class MainForm : Form
public MainForm()
{
public MainForm()
{
Title = "AM2RPortHelper";
MinimumSize = new Size(200, 200);
Title = "AM2RPortHelper";
MinimumSize = new Size(200, 200);
var mainLayout = new DynamicLayout();
mainLayout.BeginVertical();
mainLayout.AddRange(labelSelectMod,
new Label { Height = 5 },
filePicker,
labelProgress,
new Label { Height = 10 });
mainLayout.EndVertical();
mainLayout.BeginCentered();
mainLayout.AddRow(checkboxLinux, checkboxAndroid, checkboxMac);
mainLayout.AddSpace();
mainLayout.EndCentered();
mainLayout.BeginVertical();
mainLayout.AddRange(new Label { Height = 10}, buttonPort, null);
mainLayout.EndVertical();
var mainPage = new TabPage
{
Text = "Raw Mods",
Content = mainLayout
};
var am2rModLayout = new DynamicLayout();
var am2rModPage = new TabPage
{
Text = "AM2RLauncher Mods",
Content = am2rModLayout
};
Content = new TabControl
{
Pages =
{
mainPage,
am2rModPage
}
};
// events
checkboxAndroid.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxLinux.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxMac.CheckedChanged += ShouldButtonPortBeEnabled;
filePicker.FilePathChanged += ShouldButtonPortBeEnabled;
buttonPort.Click += ButtonPortOnClick;
}
private async void ButtonPortOnClick(object sender, EventArgs e)
var mainLayout = new DynamicLayout();
mainLayout.BeginVertical();
mainLayout.AddRange(labelSelectMod,
new Label { Height = 5 },
filePicker,
labelProgress,
new Label { Height = 10 });
mainLayout.EndVertical();
mainLayout.BeginCentered();
mainLayout.AddRow(checkboxLinux, checkboxAndroid, checkboxMac);
mainLayout.AddSpace();
mainLayout.EndCentered();
mainLayout.BeginVertical();
mainLayout.AddRange(new Label { Height = 10}, buttonPort, null);
mainLayout.EndVertical();
var mainPage = new TabPage
{
DisableAllElements();
PortHelper.OutputHandlerDelegate handler = output => Application.Instance.Invoke(() => labelProgress.Text = $"Info: {output}");
string modZipPath = filePicker.FilePath;
string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
string linuxPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_LINUX.zip";
string androidPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_ANDROID.apk";
string macPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_MACOS.zip";
if (File.Exists(linuxPath))
File.Delete(linuxPath);
if (File.Exists(androidPath))
File.Delete(androidPath);
if (File.Exists(macPath))
File.Delete(macPath);
if (checkboxLinux.Checked.Value)
await Task.Run(() => PortHelper.PortWindowsToLinux(modZipPath,linuxPath, handler));
if (checkboxAndroid.Checked.Value)
await Task.Run(() =>PortHelper.PortWindowsToAndroid(modZipPath, androidPath, handler));
if (checkboxMac.Checked.Value)
Text = "Raw Mods",
Content = mainLayout
};
var am2rModLayout = new DynamicLayout();
var am2rModPage = new TabPage
{
Text = "AM2RLauncher Mods",
Content = am2rModLayout
};
Content = new TabControl
{
Pages =
{
string modName = "foo";//MessageBox.Show()
await Task.Run(() => PortHelper.PortWindowsToMac(modZipPath, macPath, modName, handler));
mainPage,
am2rModPage
}
};
// events
checkboxAndroid.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxLinux.CheckedChanged += ShouldButtonPortBeEnabled;
checkboxMac.CheckedChanged += ShouldButtonPortBeEnabled;
filePicker.FilePathChanged += ShouldButtonPortBeEnabled;
buttonPort.Click += ButtonPortOnClick;
}
private async void ButtonPortOnClick(object sender, EventArgs e)
{
DisableAllElements();
labelProgress.Text = "Done!";
OpenFolder(currentDir);
EnableAllElements();
}
PortHelper.OutputHandlerDelegate handler = output => Application.Instance.Invoke(() => labelProgress.Text = $"Info: {output}");
string modZipPath = filePicker.FilePath;
string currentDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
string linuxPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_LINUX.zip";
string androidPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_ANDROID.apk";
string macPath = $"{currentDir}/{Path.GetFileNameWithoutExtension(modZipPath)}_MACOS.zip";
public static void OpenFolder(string path)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Process.Start("explorer.exe", $"\"{path}\"");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Process.Start("xdg-open", $"\"{path}\"");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Process.Start("open", $"\"{path}\"");
}
if (File.Exists(linuxPath))
File.Delete(linuxPath);
if (File.Exists(androidPath))
File.Delete(androidPath);
if (File.Exists(macPath))
File.Delete(macPath);
private void ShouldButtonPortBeEnabled(object sender, EventArgs e)
if (checkboxLinux.Checked.Value)
await Task.Run(() => PortHelper.PortWindowsToLinux(modZipPath,linuxPath, handler));
if (checkboxAndroid.Checked.Value)
await Task.Run(() =>PortHelper.PortWindowsToAndroid(modZipPath, androidPath, handler));
if (checkboxMac.Checked.Value)
{
// any checkbox + selected mod
if ((checkboxAndroid.Checked.Value || checkboxLinux.Checked.Value || checkboxMac.Checked.Value)
&& !String.IsNullOrWhiteSpace(filePicker.FilePath))
buttonPort.Enabled = true;
else
buttonPort.Enabled = false;
string modName = "foo";//MessageBox.Show()
await Task.Run(() => PortHelper.PortWindowsToMac(modZipPath, macPath, modName, handler));
}
private void DisableAllElements()
{
checkboxAndroid.Enabled = false;
checkboxLinux.Enabled = false;
checkboxMac.Enabled = false;
filePicker.Enabled = false;
buttonPort.Enabled = false;
}
labelProgress.Text = "Done!";
OpenFolder(currentDir);
private void EnableAllElements()
{
checkboxAndroid.Enabled = true;
checkboxLinux.Enabled = true;
checkboxMac.Enabled = true;
filePicker.Enabled = true;
EnableAllElements();
}
public static void OpenFolder(string path)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Process.Start("explorer.exe", $"\"{path}\"");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
Process.Start("xdg-open", $"\"{path}\"");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Process.Start("open", $"\"{path}\"");
}
private void ShouldButtonPortBeEnabled(object sender, EventArgs e)
{
// any checkbox + selected mod
if ((checkboxAndroid.Checked.Value || checkboxLinux.Checked.Value || checkboxMac.Checked.Value)
&& !String.IsNullOrWhiteSpace(filePicker.FilePath))
buttonPort.Enabled = true;
}
else
buttonPort.Enabled = false;
}
private Label labelSelectMod = new Label
{
Text = "Select Mod:"
};
private FilePicker filePicker = new FilePicker()
{
Filters = { new FileFilter("Zip file", "*.zip") }
};
private void DisableAllElements()
{
checkboxAndroid.Enabled = false;
checkboxLinux.Enabled = false;
checkboxMac.Enabled = false;
filePicker.Enabled = false;
buttonPort.Enabled = false;
}
private void EnableAllElements()
{
checkboxAndroid.Enabled = true;
checkboxLinux.Enabled = true;
checkboxMac.Enabled = true;
filePicker.Enabled = true;
buttonPort.Enabled = true;
}
private CheckBox checkboxLinux = new CheckBox()
{
Text = "Linux"
};
private CheckBox checkboxAndroid = new CheckBox()
{
Text = "Android"
};
private CheckBox checkboxMac = new CheckBox()
{
Text = "Mac"
};
private Label labelSelectMod = new Label
{
Text = "Select Mod:"
};
private FilePicker filePicker = new FilePicker()
{
Filters = { new FileFilter("Zip file", "*.zip") }
};
private Button buttonPort = new Button()
{
Text = "Port!",
Enabled = false
};
private CheckBox checkboxLinux = new CheckBox()
{
Text = "Linux"
};
private CheckBox checkboxAndroid = new CheckBox()
{
Text = "Android"
};
private CheckBox checkboxMac = new CheckBox()
{
Text = "Mac"
};
private Label labelProgress = new Label()
{
Text = "Info: "
};
}
private Button buttonPort = new Button()
{
Text = "Port!",
Enabled = false
};
private Label labelProgress = new Label()
{
Text = "Info: "
};
}
Loading…
Cancel
Save