From 1661f9a5bd46dbd7d2586787c55bfc407c027629 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 23 Jun 2017 20:20:38 -0400 Subject: hacking work Me: [squeaky] IT'S WORKING!! Phil: Michael... You just creeped me out... --- ShiftOS.MFSProfiler/Infobox.Designer.cs | 169 +++++++++++++++++++++++++ ShiftOS.MFSProfiler/Infobox.cs | 87 +++++++++++++ ShiftOS.MFSProfiler/Infobox.resx | 120 ++++++++++++++++++ ShiftOS.MFSProfiler/Main.Designer.cs | 45 ++++++- ShiftOS.MFSProfiler/Main.cs | 96 +++++++++++++- ShiftOS.MFSProfiler/ShiftOS.MFSProfiler.csproj | 9 ++ 6 files changed, 520 insertions(+), 6 deletions(-) create mode 100644 ShiftOS.MFSProfiler/Infobox.Designer.cs create mode 100644 ShiftOS.MFSProfiler/Infobox.cs create mode 100644 ShiftOS.MFSProfiler/Infobox.resx (limited to 'ShiftOS.MFSProfiler') diff --git a/ShiftOS.MFSProfiler/Infobox.Designer.cs b/ShiftOS.MFSProfiler/Infobox.Designer.cs new file mode 100644 index 0000000..2726ebb --- /dev/null +++ b/ShiftOS.MFSProfiler/Infobox.Designer.cs @@ -0,0 +1,169 @@ +namespace ShiftOS.MFSProfiler +{ + partial class Infobox + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.panel1 = new System.Windows.Forms.Panel(); + this.txtinput = new System.Windows.Forms.TextBox(); + this.lbmessage = new System.Windows.Forms.Label(); + this.flyesno = new System.Windows.Forms.FlowLayoutPanel(); + this.btnyes = new System.Windows.Forms.Button(); + this.btnno = new System.Windows.Forms.Button(); + this.btnok = new System.Windows.Forms.Button(); + this.pbicon = new System.Windows.Forms.PictureBox(); + this.panel1.SuspendLayout(); + this.flyesno.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pbicon)).BeginInit(); + this.SuspendLayout(); + // + // panel1 + // + this.panel1.Controls.Add(this.txtinput); + this.panel1.Controls.Add(this.lbmessage); + this.panel1.Controls.Add(this.flyesno); + this.panel1.Controls.Add(this.btnok); + this.panel1.Controls.Add(this.pbicon); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(325, 138); + this.panel1.TabIndex = 0; + // + // txtinput + // + this.txtinput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtinput.Location = new System.Drawing.Point(88, 77); + this.txtinput.Name = "txtinput"; + this.txtinput.Size = new System.Drawing.Size(234, 20); + this.txtinput.TabIndex = 4; + // + // lbmessage + // + this.lbmessage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lbmessage.Location = new System.Drawing.Point(85, 19); + this.lbmessage.Name = "lbmessage"; + this.lbmessage.Size = new System.Drawing.Size(237, 55); + this.lbmessage.TabIndex = 3; + this.lbmessage.Text = "label1"; + this.lbmessage.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // flyesno + // + this.flyesno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.flyesno.AutoSize = true; + this.flyesno.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flyesno.Controls.Add(this.btnyes); + this.flyesno.Controls.Add(this.btnno); + this.flyesno.Location = new System.Drawing.Point(129, 95); + this.flyesno.Name = "flyesno"; + this.flyesno.Size = new System.Drawing.Size(78, 29); + this.flyesno.TabIndex = 2; + this.flyesno.WrapContents = false; + // + // btnyes + // + this.btnyes.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnyes.AutoSize = true; + this.btnyes.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnyes.Location = new System.Drawing.Point(3, 3); + this.btnyes.Name = "btnyes"; + this.btnyes.Size = new System.Drawing.Size(35, 23); + this.btnyes.TabIndex = 4; + this.btnyes.Text = "Yes"; + this.btnyes.UseVisualStyleBackColor = true; + this.btnyes.Click += new System.EventHandler(this.btnyes_Click); + // + // btnno + // + this.btnno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnno.AutoSize = true; + this.btnno.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnno.Location = new System.Drawing.Point(44, 3); + this.btnno.Name = "btnno"; + this.btnno.Size = new System.Drawing.Size(31, 23); + this.btnno.TabIndex = 3; + this.btnno.Text = "No"; + this.btnno.UseVisualStyleBackColor = true; + this.btnno.Click += new System.EventHandler(this.btnno_Click); + // + // btnok + // + this.btnok.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.btnok.AutoSize = true; + this.btnok.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnok.Location = new System.Drawing.Point(149, 101); + this.btnok.Name = "btnok"; + this.btnok.Size = new System.Drawing.Size(32, 23); + this.btnok.TabIndex = 1; + this.btnok.Text = "OK"; + this.btnok.UseVisualStyleBackColor = true; + this.btnok.Click += new System.EventHandler(this.btnok_Click); + // + // pbicon + // + this.pbicon.Location = new System.Drawing.Point(14, 19); + this.pbicon.Name = "pbicon"; + this.pbicon.Size = new System.Drawing.Size(64, 64); + this.pbicon.TabIndex = 0; + this.pbicon.TabStop = false; + // + // Infobox + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(325, 138); + this.Controls.Add(this.panel1); + this.Name = "Infobox"; + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.flyesno.ResumeLayout(false); + this.flyesno.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pbicon)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.Label lbmessage; + private System.Windows.Forms.FlowLayoutPanel flyesno; + private System.Windows.Forms.Button btnyes; + private System.Windows.Forms.Button btnno; + private System.Windows.Forms.Button btnok; + private System.Windows.Forms.PictureBox pbicon; + private System.Windows.Forms.TextBox txtinput; + } +} \ No newline at end of file diff --git a/ShiftOS.MFSProfiler/Infobox.cs b/ShiftOS.MFSProfiler/Infobox.cs new file mode 100644 index 0000000..a30ac5a --- /dev/null +++ b/ShiftOS.MFSProfiler/Infobox.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShiftOS.MFSProfiler +{ + public partial class Infobox : Form + { + public Infobox() + { + InitializeComponent(); + } + + public Action TextCallback = null; + public Action YesNoCallback = null; + + public string MessageText + { + get + { + return lbmessage.Text; + } + set + { + lbmessage.Text = value; + } + } + + public bool ShowText + { + get { return txtinput.Visible; } + set { txtinput.Visible = value; } + } + + public bool ShowYesNo + { + get { return btnyes.Parent.Visible; } + set { btnyes.Parent.Visible = value; } + } + + public static void PromptYesNo(string title, string message, Action callback) + { + var inf = new Infobox(); + inf.ShowText = false; + inf.ShowYesNo = true; + inf.Text = title; + inf.MessageText = message; + inf.YesNoCallback = callback; + inf.ShowDialog(); + } + + public static void PromptText(string title, string message, Action callback) + { + var inf = new Infobox(); + inf.ShowYesNo = false; + inf.ShowText = true; + inf.Text = title; + inf.MessageText = message; + inf.TextCallback = callback; + inf.ShowDialog(); + } + + private void btnyes_Click(object sender, EventArgs e) + { + YesNoCallback?.Invoke(true); + this.Close(); + } + + private void btnno_Click(object sender, EventArgs e) + { + YesNoCallback?.Invoke(false); + this.Close(); + } + + private void btnok_Click(object sender, EventArgs e) + { + TextCallback?.Invoke(txtinput.Text); + this.Close(); + } + } +} diff --git a/ShiftOS.MFSProfiler/Infobox.resx b/ShiftOS.MFSProfiler/Infobox.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.MFSProfiler/Infobox.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 diff --git a/ShiftOS.MFSProfiler/Main.Designer.cs b/ShiftOS.MFSProfiler/Main.Designer.cs index 83e9b72..d97c5b9 100644 --- a/ShiftOS.MFSProfiler/Main.Designer.cs +++ b/ShiftOS.MFSProfiler/Main.Designer.cs @@ -56,6 +56,7 @@ namespace ShiftOS.MFSProfiler this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.tvfiles = new System.Windows.Forms.TreeView(); this.panel1 = new System.Windows.Forms.Panel(); + this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.pnlfileinfo = new System.Windows.Forms.Panel(); this.groupBox2 = new System.Windows.Forms.GroupBox(); @@ -71,6 +72,8 @@ namespace ShiftOS.MFSProfiler this.newFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.newDirectoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportToMFSFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.button3 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -115,6 +118,8 @@ namespace ShiftOS.MFSProfiler // // panel1 // + this.panel1.Controls.Add(this.button3); + this.panel1.Controls.Add(this.button2); this.panel1.Controls.Add(this.button1); this.panel1.Dock = System.Windows.Forms.DockStyle.Top; this.panel1.Location = new System.Drawing.Point(0, 0); @@ -122,6 +127,16 @@ namespace ShiftOS.MFSProfiler this.panel1.Size = new System.Drawing.Size(246, 30); this.panel1.TabIndex = 1; // + // button2 + // + this.button2.Location = new System.Drawing.Point(86, 4); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 1; + this.button2.Text = "Create New"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // // button1 // this.button1.Location = new System.Drawing.Point(4, 4); @@ -237,14 +252,15 @@ namespace ShiftOS.MFSProfiler this.ctxfileoptions.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.newFileToolStripMenuItem, this.newDirectoryToolStripMenuItem, - this.deleteToolStripMenuItem}); + this.deleteToolStripMenuItem, + this.exportToMFSFileToolStripMenuItem}); this.ctxfileoptions.Name = "ctxfileoptions"; - this.ctxfileoptions.Size = new System.Drawing.Size(153, 92); + this.ctxfileoptions.Size = new System.Drawing.Size(171, 92); // // newFileToolStripMenuItem // this.newFileToolStripMenuItem.Name = "newFileToolStripMenuItem"; - this.newFileToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.newFileToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.newFileToolStripMenuItem.Text = "New file"; this.newFileToolStripMenuItem.Click += new System.EventHandler(this.newFileToolStripMenuItem_Click); // @@ -253,13 +269,31 @@ namespace ShiftOS.MFSProfiler this.newDirectoryToolStripMenuItem.Name = "newDirectoryToolStripMenuItem"; this.newDirectoryToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.newDirectoryToolStripMenuItem.Text = "New directory"; + this.newDirectoryToolStripMenuItem.Click += new System.EventHandler(this.newDirectoryToolStripMenuItem_Click); // // deleteToolStripMenuItem // this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - this.deleteToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.deleteToolStripMenuItem.Text = "Delete"; // + // exportToMFSFileToolStripMenuItem + // + this.exportToMFSFileToolStripMenuItem.Name = "exportToMFSFileToolStripMenuItem"; + this.exportToMFSFileToolStripMenuItem.Size = new System.Drawing.Size(170, 22); + this.exportToMFSFileToolStripMenuItem.Text = "Export To MFS File"; + this.exportToMFSFileToolStripMenuItem.Click += new System.EventHandler(this.exportToMFSFileToolStripMenuItem_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(167, 3); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 2; + this.button3.Text = "From Dir"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -306,6 +340,9 @@ namespace ShiftOS.MFSProfiler private System.Windows.Forms.ToolStripMenuItem newFileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem newDirectoryToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.ToolStripMenuItem exportToMFSFileToolStripMenuItem; + private System.Windows.Forms.Button button3; } } diff --git a/ShiftOS.MFSProfiler/Main.cs b/ShiftOS.MFSProfiler/Main.cs index 39f087c..41e170e 100644 --- a/ShiftOS.MFSProfiler/Main.cs +++ b/ShiftOS.MFSProfiler/Main.cs @@ -135,9 +135,101 @@ System path: {tvfiles.SelectedNode.Tag.ToString()}"; private void newFileToolStripMenuItem_Click(object sender, EventArgs e) { - var fCreator = new FileCreator(tvfiles.SelectedNode.Tag.ToString()); - if(fCreator.ShowDialog() == DialogResult.OK) + var opener = new OpenFileDialog(); + opener.Title = "Import file into ShiftFS"; + opener.Filter = "All files|*.*"; + opener.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + if (opener.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + var bytes = System.IO.File.ReadAllBytes(opener.FileName); + WriteAllBytes(tvfiles.SelectedNode.Tag.ToString() + "/" + opener.SafeFileName, bytes); + SetupTree(); + } + } + + private void button2_Click(object sender, EventArgs e) + { + Infobox.PromptText("Create filesystem", "Please name your file system.", (result) => + { + if(string.IsNullOrWhiteSpace(result)) + MessageBox.Show(text: "ShiftFS does not allow blank volume names.", caption: "Volume name can't be blank", icon: MessageBoxIcon.Error, buttons:MessageBoxButtons.OK); + else + { + var dir = new Directory(); + dir.Name = result; + dir.permissions = Objects.UserPermissions.Guest; + Mounts.Add(dir); + SetupTree(); + } + }); + } + + private void newDirectoryToolStripMenuItem_Click(object sender, EventArgs e) + { + if (DirectoryExists(tvfiles.SelectedNode.Tag.ToString())) { + Infobox.PromptText("New directory", "Please name your directory.", (result) => + { + if (string.IsNullOrWhiteSpace(result)) + MessageBox.Show(text: "ShiftFS does not allow blank directory names.", caption: "Directory name can't be blank", icon: MessageBoxIcon.Error, buttons: MessageBoxButtons.OK); + else + { + var dinf = GetDirectoryInfo(tvfiles.SelectedNode.Tag.ToString()); + dinf.AddDirectory(new Directory + { + Name = result, + permissions = Objects.UserPermissions.Guest + }); + SetupTree(); + } + }); + } + } + + public void Import(string win, string sfs) + { + foreach(var dir in System.IO.Directory.GetDirectories(win)) + { + var dinf = new System.IO.DirectoryInfo(dir); + CreateDirectory(sfs + dinf.Name); + Import(dir, sfs + dinf.Name + "/"); + } + foreach(var file in System.IO.Directory.GetFiles(win)) + { + var finf = new System.IO.FileInfo(file); + WriteAllBytes(sfs + finf.Name, System.IO.File.ReadAllBytes(file)); + } + } + + private void exportToMFSFileToolStripMenuItem_Click(object sender, EventArgs e) + { + string path = tvfiles.SelectedNode.Tag.ToString(); + string[] split = path.Split('/'); + int number = Convert.ToInt32(split[0].Replace(":", "")); + string json = ExportMount(number); + var saver = new SaveFileDialog(); + saver.Filter = "MFS/ShiftFS file (Why the fuck do we also call it \".mfs\"?)|*.mfs"; + saver.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + if (saver.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + System.IO.File.WriteAllText(saver.FileName, json); + } + } + + private void button3_Click(object sender, EventArgs e) + { + var picker = new FolderBrowserDialog(); + if(picker.ShowDialog() == DialogResult.OK) + { + var inf = new System.IO.DirectoryInfo(picker.SelectedPath); + var dir = new Directory + { + Name = inf.Name, + permissions = Objects.UserPermissions.Guest, + }; + Mounts.Add(dir); + string mpath = (Mounts.Count - 1) + ":/"; + Import(inf.FullName, mpath); SetupTree(); } } diff --git a/ShiftOS.MFSProfiler/ShiftOS.MFSProfiler.csproj b/ShiftOS.MFSProfiler/ShiftOS.MFSProfiler.csproj index f1f944b..194e038 100644 --- a/ShiftOS.MFSProfiler/ShiftOS.MFSProfiler.csproj +++ b/ShiftOS.MFSProfiler/ShiftOS.MFSProfiler.csproj @@ -52,6 +52,12 @@ FileCreator.cs + + Form + + + Infobox.cs + Form @@ -63,6 +69,9 @@ FileCreator.cs + + Infobox.cs + Main.cs -- cgit v1.2.3