Histacom2/Histacom2.Engine/FileDialogBoxManager.cs

63 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2017-08-23 13:38:40 -04:00
namespace Histacom2.Engine
{
public static class FileDialogBoxManager
{
public static bool IsInOpenDialog = false;
public static bool IsInSaveDialog = false;
2017-11-04 13:48:05 -04:00
public static List<string> OnlyViewExtension = new List<string>();
2017-08-18 09:56:56 -04:00
2017-11-04 13:48:05 -04:00
public static void ActivateOpenFileDialog(params string[] ExtensionToView)
{
IsInOpenDialog = true;
IsInSaveDialog = false;
2017-11-04 13:48:05 -04:00
OnlyViewExtension = ExtensionToView.ToList();
}
2017-11-04 13:48:05 -04:00
public static void ActivateSaveFileDialog(params string[] ExtensionToView)
{
IsInOpenDialog = false;
IsInSaveDialog = true;
2017-11-04 13:48:05 -04:00
OnlyViewExtension = ExtensionToView.ToList();
}
public static void DeactivateFileDialog()
{
IsInOpenDialog = false;
IsInSaveDialog = false;
2017-11-04 13:48:05 -04:00
OnlyViewExtension = new List<string>();
}
public static string ReadTextFile(string path)
{
try
{
return File.ReadAllText(path);
} catch {
return "";
}
}
2017-08-18 09:56:56 -04:00
2017-08-18 15:41:45 -04:00
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);
2017-08-27 10:48:28 -04:00
info.FileIcon = 20;
2017-08-18 15:41:45 -04:00
info.ByteSize = fileBytes;
SaveSystem.CurrentSave.BytesLeft -= fileBytes;
SaveSystem.UpdateDirectoryInfo(new FileInfo(path).Directory.FullName, info);
}
}
}