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

Implemented window title version number and instance+session persistent directory memory #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,7 @@ ASALocalRun/
.localhistory/

# Executables
*.exe
*.exe
Copy link
Owner

Choose a reason for hiding this comment

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

.exe should already be in the gitignore

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't see it explicitly but the builds would be ignored here.

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/


# Scripts
*.ps1
18 changes: 18 additions & 0 deletions ArmaReforgerServerTool/Forms/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using ReforgerServerApp.Models;
using System.ComponentModel;
using Serilog;
using System.Reflection;

namespace ReforgerServerApp
{
Expand All @@ -21,6 +22,9 @@ public Main()
{
InitializeComponent();

// Set the window title with the version number
this.Text = $"ReforgerServerApp - {GetAppVersion()}";
Copy link
Owner

Choose a reason for hiding this comment

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

Should be "Arma Reforger Dedicated Server Tool", There are some messagebox constants in Utils/Constants.cs, instead of having:

. . . 
public static string WARN_MESSAGEBOX_TITLE_STR = "Arma Reforger Dedicated Server Tool - Warning";
public static string INFO_MESSAGEBOX_TITLE_STR = "Arma Reforger Dedicated Server Tool - Information";
. . .

we could have public static string APPLICATION_NAME = "Arma Reforger Dedicated Server Tool"; and each of the messagebox strings can be APPLICATION_NAME + blah and then you could refer to APPLICATION_NAME here to keep things consistent across the app


CreateServerParameterControls();

serverRunningLabel.Text = string.Empty;
Expand Down Expand Up @@ -75,6 +79,20 @@ public Main()
Mod.GetScenariosForMod("591AF5BDA9F7CE8B");
}

/// <summary>
/// Retrieves the application's version number.
/// </summary>
/// <returns>Formatted version string.</returns>
private string GetAppVersion()
Copy link
Owner

Choose a reason for hiding this comment

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

Probably shouldn't be in Main, maybe this can live in FileIOManager? There's not really a good home for it at the moment

Copy link
Owner

Choose a reason for hiding this comment

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

This could also be used to populate the About Box if put in the FileIOManager singleton. Please look into doing that :)

{
// Retrieve the version from the assembly metadata using pattern matching
return Assembly.GetExecutingAssembly().GetName().Version switch
{
{ } version => $"v{version.Major}.{version.Minor}.{version.Build}.{version.Revision}",
_ => "v0.0.0.0" // Fallback version if Version is null
};
Comment on lines +88 to +93
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer throwing on null version. It's the kind of thing that is either set or not, and it's vital for it to be set when released.

}

/// <summary>
/// Initialise tool tips for certain UI elements.
/// </summary>
Expand Down
38 changes: 35 additions & 3 deletions ArmaReforgerServerTool/Managers/FileIOManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class FileIOManager
private readonly string m_legacyModDatabaseFile = "./mod_database.txt";
private string m_steamCmdFile;
private string m_installDir;
private string lastUsedDirectory;
private FileIOManager()
{
bool modDatabaseExists = File.Exists(ToolPropertiesManager.GetInstance().GetToolProperties().modDatabaseFile);
Expand All @@ -52,6 +53,7 @@ private FileIOManager()
m_installDir = string.Empty;
m_steamCmdFile = string.Empty;
}
lastUsedDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
}

public static FileIOManager GetInstance()
Expand Down Expand Up @@ -113,13 +115,29 @@ public void ReadModsDatabase()
/// </summary>
public static void SaveConfigurationToFile()
{
FileIOManager instance = GetInstance();
using SaveFileDialog sfd = new();
sfd.InitialDirectory = Environment.SpecialFolder.UserProfile.ToString();

// Use lastUsedDirectory if available
if (!string.IsNullOrEmpty(instance.lastUsedDirectory))
{
sfd.InitialDirectory = instance.lastUsedDirectory;
Copy link
Owner

Choose a reason for hiding this comment

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

instead of calling this instance in here which I think might be a bit weird, have a getter which means we can, for static methods go FileIOManager.GetInstance().GetLastUsedDirectory(). This would make it consistent with the rest of the codebase too

}
else
{
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
}

sfd.Filter = "JSON (*.json)|*.json";
if (sfd.ShowDialog() == DialogResult.OK)
{
ConfigurationManager.GetInstance().CreateConfiguration();
SaveConfigurationToFile(sfd.FileName);
bool success = SaveConfigurationToFile(sfd.FileName);
if (success)
{
// Update lastUsedDirectory
instance.lastUsedDirectory = Path.GetDirectoryName(sfd.FileName) ?? instance.lastUsedDirectory;
Copy link
Owner

Choose a reason for hiding this comment

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

once updated, use getter here

}
}
}

Expand Down Expand Up @@ -150,14 +168,28 @@ public static bool SaveConfigurationToFile(string path)
/// </summary>
public static void LoadConfigurationFromFile()
{
FileIOManager instance = GetInstance();
Copy link
Owner

Choose a reason for hiding this comment

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

wont need with the getter

using OpenFileDialog ofd = new();
ofd.InitialDirectory = Environment.SpecialFolder.UserProfile.ToString();

// Use lastUsedDirectory if available
if (!string.IsNullOrEmpty(instance.lastUsedDirectory))
{
ofd.InitialDirectory = instance.lastUsedDirectory;
Copy link
Owner

Choose a reason for hiding this comment

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

getter

}
else
{
ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
}

ofd.Filter = "JSON (*.json)|*.json";
if (ofd.ShowDialog() == DialogResult.OK)
{
string filePath = ofd.FileName;
using StreamReader sr = File.OpenText(filePath);
ConfigurationManager.GetInstance().PopulateServerConfiguration(sr.ReadToEnd());

// Update lastUsedDirectory
instance.lastUsedDirectory = Path.GetDirectoryName(filePath) ?? instance.lastUsedDirectory;
Copy link
Owner

Choose a reason for hiding this comment

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

getter

}
}

Expand Down