string ReadDataFile(string reqDirectory, bool returnYesIfProtected = false) { string Val = ""; string directoryFileInfo; directoryFileInfo = File.ReadAllText(Path.Combine(reqDirectory, "_data.info")); FileSystemFolderInfo toRead = new FileSystemFolderInfo(); toRead = JsonConvert.DeserializeObject <FileSystemFolderInfo>(directoryFileInfo); if (returnYesIfProtected) { if (toRead.IsProtected) { return("yes"); } } else { return(toRead.Label); } return(Val); }
private void RefreshAll() { //try //{ this.mainView.Items.Clear(); foreach (string str in Directory.GetDirectories(CurrentDirectory)) { string label = ReadDataFile(str, false); ListViewItem itm = this.mainView.Items.Add(label ?? Path.GetFileName(str)); itm.ImageIndex = 1; itm.Tag = str; } foreach (string str in Directory.GetFiles(CurrentDirectory)) { ListViewItem itm; if (IsFileOpenDialog || IsFileSaveDialog) { if (!(Path.GetFileName(str) == "_data.info")) { if (onlyViewExtension.Contains(new FileInfo(str).Extension)) { itm = this.mainView.Items.Add(Path.GetFileName(str)); itm.Tag = str; } else { continue; } } else { continue; } } else { if (!(Path.GetFileName(str) == "_data.info")) { itm = this.mainView.Items.Add(Path.GetFileName(str)); itm.Tag = str; } else { continue; } } FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject <FileSystemFolderInfo>(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); foreach (var item in fsfi.Files) { Debug.Print(item.Name + " " + Path.GetFileName(str)); if (item.Name == Path.GetFileName(str)) { itm.ImageIndex = item.FileIcon; break; } } } /* * } catch (Exception ex) { * //wm.StartInfobox95("Exploring - C:", "Error with the file explorer \n" + ex.Message, Properties.Resources.Win95Info); add illegal operation dialog here later * ((Form)this.TopLevelControl).Close(); * }*/ }
private void richTextBox1_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Return) { string[] cmd = cmdPrompt.Lines[currentLine].Substring(prefix.Length).Split(' '); switch (cmd[0]) { case "dir": FileSystemFolderInfo dirinfo = JsonConvert.DeserializeObject <FileSystemFolderInfo>(File.ReadAllText(Path.Combine(workingDir, "_data.info"))); NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; nfi.NumberDecimalDigits = 0; output = $" Volume in drive C has no label\n Volume Serial Number is 0000-0000\n Directory of {prefix.Replace(">", "")}\n\n"; foreach (THDirInfo thd in dirinfo.SubDirs) { string dirline = new string(' ', 50); dirline = dirline.Insert(0, thd.DOSName); dirline = dirline.Insert(15, "<DIR>"); output += dirline + Environment.NewLine; } foreach (THFileInfo thfi in dirinfo.Files) { string[] dosname = thfi.DOSName.Split('.'); string dirline = new string(' ', 50); dirline = dirline.Insert(0, dosname[0]); dirline = dirline.Insert(9, dosname[1]); dirline = dirline.Insert(26 - thfi.ByteSize.ToString("N", nfi).Length, thfi.ByteSize.ToString("N", nfi)); output += dirline + Environment.NewLine; } string fline = new string(' ', 50); fline = fline.Insert(10 - dirinfo.Files.Count.ToString("N", nfi).Length, dirinfo.Files.Count.ToString("N", nfi)); fline = fline.Insert(11, "file(s)"); fline = fline.Insert(33 - dirinfo.ByteSize.ToString("N", nfi).Length, dirinfo.ByteSize.ToString("N", nfi)); fline = fline.Insert(34, "bytes"); output += fline + Environment.NewLine; string dline = new string(' ', 50); dline = dline.Insert(10 - dirinfo.SubDirs.Count.ToString("N", nfi).Length, dirinfo.SubDirs.Count.ToString("N", nfi)); dline = dline.Insert(11, "dir(s)"); dline = dline.Insert(33 - SaveSystem.CurrentSave.BytesLeft.ToString("N", nfi).Length, SaveSystem.CurrentSave.BytesLeft.ToString("N", nfi)); dline = dline.Insert(34, "bytes free"); output += dline; break; default: // Temporary CMD redirect /* * Process p = new Process(); * * p.StartInfo.UseShellExecute = false; * p.StartInfo.RedirectStandardOutput = true; * p.StartInfo.CreateNoWindow = true; * p.StartInfo.WorkingDirectory = startupDir; * p.StartInfo.FileName = "cmd.exe"; * p.StartInfo.Arguments = $"/C {cmdPrompt.Lines[currentLine].Substring(prefix.Length)}"; * p.Start(); * * output = p.StandardOutput.ReadToEnd(); */ output = "Bad command or file name"; break; } cmdPrompt.Focus(); cmdPrompt.AppendText($"\n{output}"); // Append the command output int numLines = output.Split('\n').Length; // Get the number of lines from the command output currentLine = currentLine + 2 + numLines; // Set the current line to equals the previous line plus 2 plus the number of lines from the command cmdPrompt.AppendText($"\n\n{prefix}"); // Append the text to the RichTextBox } }