Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Automatically opens log file for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
petemc89 committed Sep 21, 2020
1 parent 42e7efb commit c0401c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CraxcelLibrary/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Logger
{
public List<string> Log { get; } = new List<string>();

private FileInfo LogFile { get; }
public FileInfo LogFile { get; }

public Logger()
{
Expand Down
50 changes: 24 additions & 26 deletions FormUI/ApplicationForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ApplicationForm()

private void addFilesButton_Click(object sender, EventArgs e)
{
DisableAllButtons();
ToggleAllButtons(false);

OpenFileDialog openFileDialog = new OpenFileDialog()
{
Expand All @@ -45,20 +45,20 @@ string SupportedApplicationsFileDialogFilter()

sb.Append("Supported Applications |");

foreach (var extension in CraxcelLibrary.ApplicationSettings.SUPPORTED_APPLICATIONS.Keys)
foreach (var extension in ApplicationSettings.SUPPORTED_APPLICATIONS.Keys)
{
sb.Append($"*{extension};");
}

return sb.ToString();
}

EnableAllButtons();
ToggleAllButtons(true);
}

private void removeSelectedButton_Click(object sender, EventArgs e)
{
DisableAllButtons();
ToggleAllButtons(false);

var selectedItems = fileListBox.SelectedItems;

Expand All @@ -67,27 +67,27 @@ private void removeSelectedButton_Click(object sender, EventArgs e)
fileListBox.Items.Remove(selectedItems[i]);
}

EnableAllButtons();
ToggleAllButtons(true);
}

private void clearAllFilesButton_Click(object sender, EventArgs e)
{
DisableAllButtons();
ToggleAllButtons(false);

fileListBox.Items.Clear();

EnableAllButtons();
ToggleAllButtons(true);
}

private void unlockFilesButton_Click(object sender, EventArgs e)
{
DisableAllButtons();
ToggleAllButtons(false);

var confirmation = MessageBox.Show("Ready to start craXcel?", "Confirm", MessageBoxButtons.YesNo);

if (confirmation == DialogResult.No || fileListBox.Items.Count == 0)
{
EnableAllButtons();
ToggleAllButtons(true);

return;
}
Expand Down Expand Up @@ -120,20 +120,30 @@ private void unlockFilesButton_Click(object sender, EventArgs e)
progressBar.Value++;
}

logger.Add($"{filesUnlocked}/{fileListBox.Items.Count} files unlocked");
logger.Add("craXcel finished");

logger.Save();

MessageBox.Show($"{filesUnlocked}/{fileListBox.Items.Count} files unlocked.", "Complete");

// TO-DO - Implement additional OS support
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start("explorer.exe", ApplicationSettings.CRAXCEL_DIR.FullName);
{
try
{
Process.Start("explorer.exe", ApplicationSettings.CRAXCEL_DIR.FullName);
Process.Start("notepad.exe", logger.LogFile.FullName);
}
catch
{

}
}

ResetForm();

EnableAllButtons();
ToggleAllButtons(true);
}

private void openOptionsFormButton_Click(object sender, EventArgs e)
Expand All @@ -149,26 +159,14 @@ private void ResetForm()
progressBar.Value = 0;
}

private void DisableAllButtons()
{
foreach (Control control in this.Controls)
{
if (control is Button)
{
var btn = (Button)control;
btn.Enabled = false;
}
}
}

private void EnableAllButtons()
private void ToggleAllButtons(bool enableButtons)
{
foreach (Control control in this.Controls)
{
if (control is Button)
{
var btn = (Button)control;
btn.Enabled = true;
btn.Enabled = enableButtons;
}
}
}
Expand Down

0 comments on commit c0401c1

Please sign in to comment.