diff --git a/CraxcelLibrary/CraxcelProcessor.cs b/CraxcelLibrary/CraxcelProcessor.cs
index 4e6cf41..7d45be5 100644
--- a/CraxcelLibrary/CraxcelProcessor.cs
+++ b/CraxcelLibrary/CraxcelProcessor.cs
@@ -1,7 +1,9 @@
using craXcel;
-using System;
+using System.Linq;
+using System.Collections.Generic;
using System.IO;
using static CraxcelLibrary.Enums;
+using CraxcelLibrary.Interfaces;
namespace CraxcelLibrary
{
@@ -10,30 +12,51 @@ namespace CraxcelLibrary
///
public static class CraxcelProcessor
{
-
///
- /// Unlocks the specified file within the option parameters set by the user.
+ /// Main entry point from the UI.
///
- /// The filepath of the file to unlock.
- /// Bool stating if the file was successfully unlocked.
- public static bool UnlockFile(string filePath, Logger logger)
+ /// The file paths of those files being unlocked.
+ /// The number of successfully unlocked files.
+ public static int UnlockFiles(List filePaths, ILogger logger = null)
{
- try
+ if (logger == null)
+ {
+ logger = new TextFileLogger();
+ }
+
+ logger.Add($"craXcel started");
+ logger.Add($"{filePaths.Count} files selected");
+
+ int filesUnlocked = 0;
+
+ foreach (var filePath in filePaths)
{
var file = new FileInfo(filePath);
- SupportedApplication application = IdentifyApplication(file);
+ try
+ {
+ SupportedApplication application = IdentifyApplication(file);
- ILockedFile lockedFile = CreateLockedFileInstance(file, application);
+ ILockedFile lockedFile = CreateLockedFileInstance(file, application);
- lockedFile.Unlock();
+ lockedFile.Unlock();
- return true;
- }
- catch
- {
- return false;
+ filesUnlocked++;
+
+ logger.Add($"Successfully unlocked: {file.Name} ({file.FullName})");
+ }
+ catch
+ {
+ logger.Add($"Failed to unlock: {file.Name} ({file.FullName})");
+ }
}
+
+ logger.Add($"{filesUnlocked}/{filePaths.Count} files unlocked");
+ logger.Add("craXcel finished");
+
+ logger.Save();
+
+ return filesUnlocked;
}
private static SupportedApplication IdentifyApplication(FileInfo file)
diff --git a/CraxcelLibrary/Interfaces/ILogger.cs b/CraxcelLibrary/Interfaces/ILogger.cs
new file mode 100644
index 0000000..b065cc1
--- /dev/null
+++ b/CraxcelLibrary/Interfaces/ILogger.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace CraxcelLibrary.Interfaces
+{
+ public interface ILogger
+ {
+ public List Log { get; }
+
+ public void Add(string logMessage);
+
+ public void Save();
+ }
+}
diff --git a/CraxcelLibrary/Logger.cs b/CraxcelLibrary/TextFileLogger.cs
similarity index 91%
rename from CraxcelLibrary/Logger.cs
rename to CraxcelLibrary/TextFileLogger.cs
index d1d622b..9232377 100644
--- a/CraxcelLibrary/Logger.cs
+++ b/CraxcelLibrary/TextFileLogger.cs
@@ -1,4 +1,5 @@
-using System;
+using CraxcelLibrary.Interfaces;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -8,13 +9,13 @@ namespace CraxcelLibrary
///
/// Basic logger, writing lines to a list of strings and then outputting that list to a text file.
///
- public class Logger
+ public class TextFileLogger : ILogger
{
public List Log { get; } = new List();
public FileInfo LogFile { get; }
- public Logger()
+ public TextFileLogger()
{
var dateTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");
var fileName = $"log_{dateTime}.txt";
diff --git a/FormUI/ApplicationForm.Designer.cs b/FormUI/ApplicationForm.Designer.cs
index 46f345e..e6c380e 100644
--- a/FormUI/ApplicationForm.Designer.cs
+++ b/FormUI/ApplicationForm.Designer.cs
@@ -33,11 +33,11 @@ private void InitializeComponent()
this.addFilesButton = new System.Windows.Forms.Button();
this.removeSelectedButton = new System.Windows.Forms.Button();
this.clearAllFilesButton = new System.Windows.Forms.Button();
- this.progressBar = new System.Windows.Forms.ProgressBar();
this.unlockFilesButton = new System.Windows.Forms.Button();
this.fileListLabel = new System.Windows.Forms.Label();
this.openOptionsFormButton = new System.Windows.Forms.Button();
this.craxcelNote = new System.Windows.Forms.Label();
+ this.githubLink = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// fileListBox
@@ -88,19 +88,11 @@ private void InitializeComponent()
this.clearAllFilesButton.UseVisualStyleBackColor = false;
this.clearAllFilesButton.Click += new System.EventHandler(this.clearAllFilesButton_Click);
//
- // progressBar
- //
- this.progressBar.Location = new System.Drawing.Point(9, 400);
- this.progressBar.Name = "progressBar";
- this.progressBar.Size = new System.Drawing.Size(369, 29);
- this.progressBar.TabIndex = 2;
- this.progressBar.Tag = "";
- //
// unlockFilesButton
//
this.unlockFilesButton.BackColor = System.Drawing.Color.Green;
this.unlockFilesButton.ForeColor = System.Drawing.Color.White;
- this.unlockFilesButton.Location = new System.Drawing.Point(465, 400);
+ this.unlockFilesButton.Location = new System.Drawing.Point(240, 400);
this.unlockFilesButton.Name = "unlockFilesButton";
this.unlockFilesButton.Size = new System.Drawing.Size(150, 29);
this.unlockFilesButton.TabIndex = 1;
@@ -122,7 +114,7 @@ private void InitializeComponent()
//
this.openOptionsFormButton.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.openOptionsFormButton.ForeColor = System.Drawing.Color.DimGray;
- this.openOptionsFormButton.Location = new System.Drawing.Point(384, 400);
+ this.openOptionsFormButton.Location = new System.Drawing.Point(9, 400);
this.openOptionsFormButton.Name = "openOptionsFormButton";
this.openOptionsFormButton.Size = new System.Drawing.Size(75, 29);
this.openOptionsFormButton.TabIndex = 1;
@@ -135,12 +127,24 @@ private void InitializeComponent()
this.craxcelNote.AutoSize = true;
this.craxcelNote.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.craxcelNote.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
- this.craxcelNote.Location = new System.Drawing.Point(9, 377);
+ this.craxcelNote.Location = new System.Drawing.Point(79, 378);
this.craxcelNote.Name = "craxcelNote";
this.craxcelNote.Size = new System.Drawing.Size(474, 13);
this.craxcelNote.TabIndex = 4;
this.craxcelNote.Text = "craXcel will never overwrite your files, it will always create an unlocked copy o" +
"f the original.";
+ //
+ // githubLink
+ //
+ this.githubLink.AutoSize = true;
+ this.githubLink.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.githubLink.Location = new System.Drawing.Point(571, 407);
+ this.githubLink.Name = "githubLink";
+ this.githubLink.Size = new System.Drawing.Size(48, 17);
+ this.githubLink.TabIndex = 5;
+ this.githubLink.TabStop = true;
+ this.githubLink.Text = "GitHub";
+ this.githubLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.githubLink_LinkClicked);
//
// ApplicationForm
//
@@ -148,11 +152,11 @@ private void InitializeComponent()
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(624, 441);
+ this.Controls.Add(this.githubLink);
this.Controls.Add(this.craxcelNote);
this.Controls.Add(this.openOptionsFormButton);
this.Controls.Add(this.fileListLabel);
this.Controls.Add(this.unlockFilesButton);
- this.Controls.Add(this.progressBar);
this.Controls.Add(this.clearAllFilesButton);
this.Controls.Add(this.removeSelectedButton);
this.Controls.Add(this.addFilesButton);
@@ -175,11 +179,11 @@ private void InitializeComponent()
private System.Windows.Forms.Button addFilesButton;
private System.Windows.Forms.Button removeSelectedButton;
private System.Windows.Forms.Button clearAllFilesButton;
- private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Button unlockFilesButton;
private System.Windows.Forms.Label fileListLabel;
private System.Windows.Forms.Button openOptionsFormButton;
private System.Windows.Forms.Label craxcelNote;
+ private System.Windows.Forms.LinkLabel githubLink;
}
}
diff --git a/FormUI/ApplicationForm.cs b/FormUI/ApplicationForm.cs
index 97354a2..b8fce74 100644
--- a/FormUI/ApplicationForm.cs
+++ b/FormUI/ApplicationForm.cs
@@ -1,7 +1,9 @@
using CraxcelLibrary;
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
@@ -10,12 +12,9 @@ namespace FormUI
{
public partial class ApplicationForm : Form
{
- private DirectoryInfo UserHomeDirectory { get; }
-
public ApplicationForm()
{
InitializeComponent();
- UserHomeDirectory = ApplicationSettings.CRAXCEL_DIR;
}
private void addFilesButton_Click(object sender, EventArgs e)
@@ -24,7 +23,7 @@ private void addFilesButton_Click(object sender, EventArgs e)
OpenFileDialog openFileDialog = new OpenFileDialog()
{
- InitialDirectory = UserHomeDirectory.FullName,
+ InitialDirectory = ApplicationSettings.CRAXCEL_DIR.FullName,
Multiselect = true,
Filter = SupportedApplicationsFileDialogFilter()
};
@@ -92,53 +91,35 @@ private void unlockFilesButton_Click(object sender, EventArgs e)
return;
}
- progressBar.Maximum = fileListBox.Items.Count;
-
- var logger = new Logger();
- logger.Add($"craXcel started");
- logger.Add($"{fileListBox.Items.Count} files selected");
+ List filePaths = fileListBox.Items.OfType().ToList();
- var filesUnlocked = 0;
+ var logger = new TextFileLogger();
- foreach (var item in fileListBox.Items)
- {
- var filePath = item.ToString();
- var file = new FileInfo(filePath);
+ int filesUnlocked = CraxcelProcessor.UnlockFiles(filePaths, logger);
- var wasSuccessful = CraxcelProcessor.UnlockFile(filePath, logger);
+ MessageBox.Show($"{filesUnlocked}/{filePaths.Count} files unlocked.", "Complete");
- if (wasSuccessful)
+ // TO-DO - Possibly only works on Windows?
+ try
+ {
+ var craxcelDir = new ProcessStartInfo(ApplicationSettings.CRAXCEL_DIR.FullName)
{
- logger.Add($"Successfully unlocked: {file.Name} ({file.FullName})");
- filesUnlocked++;
- }
- else
+ UseShellExecute = true,
+ Verb = "open"
+ };
+
+ var logFile = new ProcessStartInfo(logger.LogFile.FullName)
{
- logger.Add($"Failed to unlock: {file.Name} ({file.FullName})");
- }
+ UseShellExecute = true,
+ Verb = "open"
+ };
- progressBar.Value++;
+ Process.Start(craxcelDir);
+ Process.Start(logFile);
}
-
- 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))
- {
- try
- {
- Process.Start("explorer.exe", ApplicationSettings.CRAXCEL_DIR.FullName);
- Process.Start("notepad.exe", logger.LogFile.FullName);
- }
- catch
- {
-
- }
+ catch
+ {
+
}
ResetForm();
@@ -150,13 +131,12 @@ private void openOptionsFormButton_Click(object sender, EventArgs e)
{
var optionsForm = new UserOptionsForm();
- optionsForm.Show();
+ optionsForm.ShowDialog();
}
private void ResetForm()
{
fileListBox.Items.Clear();
- progressBar.Value = 0;
}
private void ToggleAllButtons(bool enableButtons)
@@ -170,5 +150,18 @@ private void ToggleAllButtons(bool enableButtons)
}
}
}
+
+ private void githubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
+ {
+ var info = new ProcessStartInfo("https://github.com/petemc89/craXcel-desktop")
+ {
+ UseShellExecute = true,
+ Verb = "open"
+ };
+
+ Process.Start(info);
+
+ //Process.Start("https://github.com/petemc89/craXcel-desktop");
+ }
}
}
diff --git a/FormUI/FormUI.csproj b/FormUI/FormUI.csproj
index 663b79b..3368bb3 100644
--- a/FormUI/FormUI.csproj
+++ b/FormUI/FormUI.csproj
@@ -10,4 +10,19 @@
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
\ No newline at end of file
diff --git a/FormUI/Properties/Resources.Designer.cs b/FormUI/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..6e6ecf0
--- /dev/null
+++ b/FormUI/Properties/Resources.Designer.cs
@@ -0,0 +1,63 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace FormUI.Properties {
+ using System;
+
+
+ ///
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ ///
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Returns the cached ResourceManager instance used by this class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FormUI.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
diff --git a/FormUI/Properties/Resources.resx b/FormUI/Properties/Resources.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/FormUI/Properties/Resources.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file