From d8014b072e35c69cc6daac0d6ad127a38e664b60 Mon Sep 17 00:00:00 2001 From: steph moody Date: Sat, 31 Oct 2020 11:09:20 +0100 Subject: [PATCH 1/2] Allows the migration of liteDb4 databases to be specified as command line arguments at startup --- LiteDB.Studio/Forms/MainForm.cs | 21 ++++++++++++--------- LiteDB.Studio/Program.cs | 7 ++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/LiteDB.Studio/Forms/MainForm.cs b/LiteDB.Studio/Forms/MainForm.cs index fd16031..4d17580 100644 --- a/LiteDB.Studio/Forms/MainForm.cs +++ b/LiteDB.Studio/Forms/MainForm.cs @@ -1,15 +1,9 @@ -using ICSharpCode.TextEditor; -using LiteDB.Engine; -using LiteDB.Studio.Forms; +using LiteDB.Studio.Forms; using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -26,8 +20,17 @@ public partial class MainForm : Form private ConnectionString _connectionString = null; private SqlCodeCompletion _codeCompletion; - public MainForm(string filename) + public MainForm(string[] args) { + string filename = null; + bool upgrade = false; + + if (args.Length == 2) + { + filename = args[0]; + bool.TryParse(args[1], out upgrade); + } + InitializeComponent(); // For performance https://stackoverflow.com/questions/4255148/how-to-improve-painting-performance-of-datagridview @@ -43,7 +46,7 @@ public MainForm(string filename) } else { - this.Connect(new ConnectionString(filename)); + this.Connect(new ConnectionString(filename){Upgrade = upgrade }); } txtSql.ActiveTextAreaControl.TextArea.Caret.PositionChanged += (s, e) => diff --git a/LiteDB.Studio/Program.cs b/LiteDB.Studio/Program.cs index 96449fa..0121e99 100644 --- a/LiteDB.Studio/Program.cs +++ b/LiteDB.Studio/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; using ICSharpCode.TextEditor.Util; @@ -18,7 +15,7 @@ static void Main(string[] args) Application.ApplicationExit += OnExit; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm(args.Length == 0 ? null : args[0])); + Application.Run(new MainForm(args)); } private static void OnExit(object sender, EventArgs eventArgs) @@ -27,4 +24,4 @@ private static void OnExit(object sender, EventArgs eventArgs) AppSettingsManager.PersistData(); } } -} +} \ No newline at end of file From c64a599d5509a785b7c7c9de67cbb8330356fff3 Mon Sep 17 00:00:00 2001 From: steph moody Date: Sat, 27 Mar 2021 21:43:11 +0100 Subject: [PATCH 2/2] support variant argument lenghts --- LiteDB.Studio/Forms/MainForm.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/LiteDB.Studio/Forms/MainForm.cs b/LiteDB.Studio/Forms/MainForm.cs index 4d17580..57b6b82 100644 --- a/LiteDB.Studio/Forms/MainForm.cs +++ b/LiteDB.Studio/Forms/MainForm.cs @@ -25,9 +25,12 @@ public MainForm(string[] args) string filename = null; bool upgrade = false; - if (args.Length == 2) + if (args.Length >= 1) { filename = args[0]; + } + if (args.Length >= 2) + { bool.TryParse(args[1], out upgrade); }