public static void CreateWindowsFile(string filepath, string filename, string contents, int fileicon, int bytes) { File.WriteAllText(Path.Combine(filepath, filename), contents); THFileInfo info = new THFileInfo(); info.Name = filename; info.FileIcon = fileicon; info.ByteSize = bytes; CurrentSave.BytesLeft -= bytes; UpdateDirectoryInfo(filepath, info); }
public static void SaveRtfDocument(RichTextBox tbox, string path) { int fileBytes = 0; tbox.SaveFile(path); fileBytes = File.ReadAllText(path).Length; THFileInfo info = new THFileInfo(); info.Name = Path.GetFileName(path); info.FileIcon = 20; info.ByteSize = fileBytes; SaveSystem.CurrentSave.BytesLeft -= fileBytes; SaveSystem.UpdateDirectoryInfo(new FileInfo(path).Directory.FullName, info); }
public static void RefreshDesktopIcons(ListViewItem[] baseIcons, ref ListView view, string folder) { view.Items.Clear(); // This resets it to it's default view.Items.AddRange(baseIcons); foreach (string dir in Directory.GetDirectories(folder)) { string label = ReadDataFile(dir); view.Items.Add(label ?? Path.GetFileName(dir), 1); view.FindItemWithText(Path.GetFileName(dir)).Tag = dir; } foreach (string dir in Directory.GetFiles(folder)) { if (Path.GetFileName(dir) != "_data.info") { THFileInfo file = new THFileInfo(); FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject <FileSystemFolderInfo>(File.ReadAllText(Path.Combine(folder, "_data.info"))); foreach (THFileInfo f in fsfi.Files) { if (f.Name.ToLower() == Path.GetFileName(dir).ToLower()) { file = f; break; } } if (new FileInfo(dir).Extension == ".exe" && file.FileIcon == 8) { file.FileIcon = 10; } if (new FileInfo(dir).Extension == ".txt" && file.FileIcon == 8) { file.FileIcon = 12; } view.Items.Add(Path.GetFileName(dir), file.FileIcon); view.FindItemWithText(Path.GetFileName(dir)).Tag = dir; string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); File.WriteAllText(Path.Combine(folder, "_data.info"), toWrite); } } }
public static void UpdateDirectoryInfo(string path, THFileInfo newfile) { newfile.DOSName = newfile.Name.ToUpper().Replace("*", "").Replace("+", "").Replace(":", "").Replace(";", "").Replace(" ", ""); if (newfile.DOSName.Contains(".")) { string[] dos = newfile.DOSName.Split('.'); if (dos.Count() > 2) { List <string> dosb = dos.ToList(); dosb.RemoveRange(1, dos.Count() - 2); dos = dosb.ToArray(); } dos[1] = dos[1].Substring(0, 3); if (dos[0].Length > 8) { dos[0] = dos[0].Substring(0, 6) + "~1"; } newfile.DOSName = dos[0] + "." + dos[1]; } else if (newfile.DOSName.Length > 8) { newfile.DOSName = newfile.DOSName.Substring(0, 6) + "~1"; } if (File.ReadAllText(Path.Combine(path, "_data.info")).Contains(newfile.DOSName)) { return; } FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject <FileSystemFolderInfo>(File.ReadAllText(Path.Combine(path, "_data.info"))); fsfi.Files.Add(newfile); fsfi.ByteSize += newfile.ByteSize; string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); }