void loadDisk(string name) { treeView1.Nodes.Clear(); listView1.Items.Clear(); if (vol != null) { vol.Close(); } vol = new FATVolume(name); treeView1.Nodes.Add(new TreeNode(name.Contains("\\") ? name.Substring(name.LastIndexOf('\\') + 1) : name.Contains("/") ? name.Substring(name.LastIndexOf('/') + 1) : name, 2, 2)); getDirs(string.Empty, treeView1.Nodes[0]); treeView1.Nodes[0].Expand(); FileInfo fi1 = new FileInfo(); fi1.TreeNode = treeView1.Nodes[0]; fi1.FullPath = ""; fi1.FileName = ""; treeView1.Nodes[0].Tag = fi1; SetDir(fi1); Forward = new Stack <string>(); Back = new Stack <string>(); toolStripButtonBack.Enabled = false; toolStripButtonCopy.Enabled = false; toolStripButtonCut.Enabled = false; toolStripButtonDelete.Enabled = false; toolStripButtonForward.Enabled = false; toolStripButtonNewFolder.Enabled = true; toolStripButtonUp.Enabled = false; toolStripButtonDiskProperties.Enabled = true; toolStripButtonImport.Enabled = true; toolStripButtonExport.Enabled = true; timer1.Start(); statusStrip1.Items[1].Text = string.Format("{0} KB free", vol.ComputeFreeSpace() / 1024); }
static int Main(string[] args) { if (args[0] == "--help") { Console.WriteLine("usage:\r\nvget image-file filename [newname]\r\nvget --help"); return(0); } switch (args.Length) { case 2: case 3: if (!System.IO.File.Exists(args[0])) { Console.Error.WriteLine("vget: Disk image file does not exist."); return(1); } try { FATVolume fv = new FATVolume(args[0]); if (!fv.Exists(args[1])) { Console.Error.WriteLine("vget: File does not exist on image."); return(1); } args[1] = args[1].Replace('/', '\\'); string name = args.Length == 3 ? args[2] : args[1].Contains("\\") ? args[1].Substring(args[1].LastIndexOf('\\') + 1) : args[1]; System.IO.Stream sw = new System.IO.FileStream(name, System.IO.FileMode.Create); System.IO.Stream sr = fv.OpenFile(args[1], System.IO.FileAccess.Read, System.IO.FileMode.Open); byte[] x = new byte[1024]; while (sr.Position < sr.Length) { sw.Write(x, 0, sr.Read(x, 0, (int)Math.Min(1024, sr.Length - sr.Position))); } sr.Close(); sw.Close(); fv.Close(); } catch (Exception e) { System.Console.Error.WriteLine("vget: error: {0}", e.Message); return(1); } return(0); default: Console.Error.WriteLine("vget: wrong number of arguments given"); Console.WriteLine("usage:\r\nvget image-file filename newname\r\nvget --help"); return(1); } }
static int Main(string[] args) { if (args[0] == "--help") { Console.WriteLine("usage:\r\nvput image-file file newname\r\nvput --help"); return(0); } switch (args.Length) { case 3: if (!System.IO.File.Exists(args[0]) || !System.IO.File.Exists(args[1])) { Console.Error.WriteLine("vput: File does not exist."); return(1); } try { FATVolume fv = new FATVolume(args[0]); System.IO.Stream sr = new System.IO.FileStream(args[1], System.IO.FileMode.Open); System.IO.Stream sw = fv.OpenFile(args[2], System.IO.FileAccess.Write, System.IO.FileMode.Create); byte[] x = new byte[1024]; while (sr.Position < sr.Length) { sw.Write(x, 0, sr.Read(x, 0, (int)Math.Min(1024, sr.Length - sr.Position))); } sw.Close(); sr.Close(); fv.Close(); } catch (Exception e) { System.Console.Error.WriteLine("vput: error: {0}", e.Message); return(1); } return(0); default: Console.Error.WriteLine("vput: wrong number of arguments given"); Console.WriteLine("usage:\r\nvput image-file file newname\r\nvput --help"); return(1); } }
static int Main(string[] args) { if (args[0] == "--help") { Console.WriteLine("usage:\r\nvout image-file filename\r\nvout --help"); return(0); } switch (args.Length) { case 2: if (!System.IO.File.Exists(args[0])) { Console.Error.WriteLine("vout: Disk image file does not exist."); return(1); } try { FATVolume fv = new FATVolume(args[0]); if (!fv.Exists(args[1])) { Console.Error.WriteLine("vout: File does not exist on image."); return(1); } System.IO.StreamReader tr = new System.IO.StreamReader(fv.OpenFile(args[1], System.IO.FileAccess.Read, System.IO.FileMode.Open)); System.Console.Out.Write(tr.ReadToEnd()); tr.Close(); fv.Close(); } catch (Exception e) { System.Console.Error.WriteLine("vout: error: {0}", e.Message); return(1); } return(0); default: Console.Error.WriteLine("vout: wrong number of arguments given"); Console.WriteLine("usage:\r\nvout image-file filename\r\nvout --help"); return(1); } }
static int Main(string[] args) { switch (args.Length) { case 0: System.Console.WriteLine("usage: vmkdir image-name dir"); return(1); case 1: if (args[0] == "--help") { System.Console.WriteLine("usage: vmkdir image-name dir"); return(0); } System.Console.Error.WriteLine("missing parameter - dir"); return(1); case 2: try { FATVolume fatvol = new FATVolume(args[0]); fatvol.CreateDirectory(args[1]); fatvol.Close(); } catch (Exception e) { System.Console.Error.Write("error: "); System.Console.Error.WriteLine(e.Message); return(1); } return(0); default: System.Console.Error.WriteLine("too many paramaters"); System.Console.Error.WriteLine("usage: vmkdir image-name dir"); return(1); } }
static int Main(string[] args) { if (args[0] == "--help") { Console.WriteLine("usage:\r\nvin image-file newfile\r\nvin --help"); return(0); } switch (args.Length) { case 2: if (!System.IO.File.Exists(args[0])) { Console.Error.WriteLine("vin: Disk image file does not exist."); return(1); } try { FATVolume fv = new FATVolume(args[0]); System.IO.StreamWriter sw = new System.IO.StreamWriter(fv.OpenFile(args[1], System.IO.FileAccess.Write, System.IO.FileMode.Create)); sw.Write(Console.In.ReadToEnd()); sw.Close(); fv.Close(); } catch (Exception e) { System.Console.Error.WriteLine("vin: error: {0}", e.Message); return(1); } return(0); default: Console.Error.WriteLine("vin: wrong number of arguments given"); Console.WriteLine("usage:\r\nvin image-file newfile\r\nvin --help"); return(1); } }
static int Main(string[] args) { if (args[0] == "--help") { Console.WriteLine("usage:\r\nvexists image-file filename [-f|-d]\r\nvexists --help"); return(0); } int b = 0; FATVolume fv; switch (args.Length) { case 2: if (!System.IO.File.Exists(args[0])) { Console.Error.WriteLine("vexists: Disk image file does not exist."); return(0); } try { fv = new FATVolume(args[0]); b = fv.Exists(args[1]) == false ? 0 : 1; fv.Close(); } catch (Exception e) { System.Console.Error.WriteLine("vexists: error: {0}", e.Message); return(0); } return(b); case 3: if (!System.IO.File.Exists(args[0])) { Console.Error.WriteLine("vexists: Disk image file does not exist."); return(0); } if (args[2] != "-d" && args[2] != "-f") { Console.Error.WriteLine("vexists: Third argument is not -d or -f"); return(0); } try { fv = new FATVolume(args[0]); b = (args[2] == "-f" ? fv.FileExists(args[1]) : fv.DirectoryExists(args[1])) == false ? 0 : 1; fv.Close(); } catch (Exception e) { System.Console.Error.WriteLine("vexists: error: {0}", e.Message); return(0); } return(b); default: Console.Error.WriteLine("vexists: wrong number of arguments given"); Console.WriteLine("usage:\r\nvexists image-file filename [-f|-d]\r\nvexists --help"); return(0); } }
static int Main(string[] args) { switch (args.Length) { case 0: System.Console.WriteLine("usage: vfinfo image-name path"); return(1); case 1: if (args[0] == "--help") { System.Console.WriteLine("usage: vattr image-name path rhsa"); return(0); } System.Console.Error.WriteLine("missing parameter - path"); return(1); case 2: try { FATVolume fatvol = new FATVolume(args[0]); if (!fatvol.Exists(args[1])) { throw new Exception(string.Format("File or directory {0} does not exist on disk image.", args[1])); } FileInfo fi = fatvol.GetFileInfo(args[1]); FileAttributes a = fi.Attributes; string attr = ""; if (a == FileAttributes.None) { attr += ("(no attributes) "); } if ((a & FileAttributes.Directory) != FileAttributes.None) { attr += ("directory "); } if ((a & FileAttributes.ReadOnly) != FileAttributes.None) { attr += ("read only "); } if ((a & FileAttributes.Hidden) != FileAttributes.None) { attr += ("hidden "); } if ((a & FileAttributes.System) != FileAttributes.None) { attr += ("system "); } if ((a & FileAttributes.Archive) != FileAttributes.None) { attr += ("archive "); } Console.WriteLine(" Name:\t{0}", fi.Name); Console.WriteLine(" Attributes:\t{0}", attr); Console.WriteLine(" Size:\t{0} bytes", fi.Size); Console.WriteLine("First cluster:\t{0}", fi.FirstCluster); Console.WriteLine("Creation date:\t{0} {1}", fi.CreateTime.ToLongDateString(), fi.CreateTime.ToLongTimeString()); Console.WriteLine("Modified date:\t{0} {1}", fi.LastWriteTime.ToLongDateString(), fi.LastWriteTime.ToLongTimeString()); Console.WriteLine($" Access date:\t{fi.LastAccessDate.ToLongDateString()}"); fatvol.Close(); } catch (Exception e) { System.Console.Error.Write("error: "); System.Console.Error.WriteLine(e.Message); return(1); } return(0); default: System.Console.Error.WriteLine("too many paramaters"); System.Console.Error.WriteLine("usage: vfinfo image-name path"); return(1); } }
static int Main(string[] args) { switch (args.Length) { case 0: System.Console.WriteLine("usage: vattr image-name path rhsa"); return(1); case 1: if (args[0] == "--help") { System.Console.WriteLine("usage: vattr image-name path rhsa"); return(0); } System.Console.Error.WriteLine("missing parameter - path"); return(1); case 2: System.Console.Error.WriteLine("missing parameter - attributes"); return(1); case 3: try { FATVolume fatvol = new FATVolume(args[0]); if (!fatvol.Exists(args[1])) { throw new Exception(string.Format("File or directory {0} does not exist on disk image.", args[1])); } FileAttributes a = fatvol.GetAttributes(args[1]) & (FileAttributes.Directory); for (int i = 0; i < args[2].Length; i++) { switch (args[2][i]) { case 'r': a |= FileAttributes.ReadOnly; break; case 'h': a |= FileAttributes.Hidden; break; case 's': a |= FileAttributes.System; break; case 'a': a |= FileAttributes.Archive; break; default: throw new Exception(string.Format("Unrecognized attrubute - '{0}'", args[2][i])); } } fatvol.SetAttributes(args[1], a); fatvol.Close(); } catch (Exception e) { System.Console.Error.Write("error: "); System.Console.Error.WriteLine(e.Message); return(1); } return(0); default: System.Console.Error.WriteLine("too many paramaters"); System.Console.Error.WriteLine("usage: vattr image-name path rhsa"); return(1); } }