diff --git a/Gaia.sln b/Gaia.sln new file mode 100644 index 0000000..780c77b --- /dev/null +++ b/Gaia.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.7 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gaia", "Gaia\Gaia.csproj", "{0E9767EC-BD0D-4251-8A81-CA79B3A3DC58}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0E9767EC-BD0D-4251-8A81-CA79B3A3DC58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E9767EC-BD0D-4251-8A81-CA79B3A3DC58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E9767EC-BD0D-4251-8A81-CA79B3A3DC58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E9767EC-BD0D-4251-8A81-CA79B3A3DC58}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Gaia/Files.cs b/Gaia/Files.cs new file mode 100644 index 0000000..75c3239 --- /dev/null +++ b/Gaia/Files.cs @@ -0,0 +1,430 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; +using System.Xml; + +namespace GAIA +{ + public class Files + { + //A File to save dictionaries + public class DictionaryFile + { + private const string extension = ".dic"; + private FileInfo file; + private Dictionary dictA; + + + public DictionaryFile(string name) + { + dictA = new Dictionary(); + createDictionaryFile(name, "Data"); + } + + public DictionaryFile(string name, string directory) + { + dictA = new Dictionary(); + createDictionaryFile(name, directory); + } + + private void createDictionaryFile(string name, string directory) + { + //saving in standard directory 'Data' + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + var fn = directory + "/" + name; + + //adding the extension .list if not existing + if (!name.Contains(extension)) + { + fn += extension; + } + + file = new FileInfo(fn); + //reading the file if existent + + if (file.Exists) + { + readFile(); + } + else + { + using (StreamWriter sw = file.CreateText()) + { + + } + } + } + + private void readFile() + { + foreach (var line in File.ReadAllLines(file.FullName)) + { + try + { + var l = line.Split('|'); + dictA.Add(l[0], l[1]); + } + catch { } + } + } + + public void add(string key, string value) + { + dictA.Add(key, value); + + using (StreamWriter sw = file.AppendText()) + { + sw.WriteLine(key + "|" + value); + } + } + + public void remove(string key) + { + //removing the item by key + dictA.Remove(key); + var lines = File.ReadAllLines(file.FullName); + + using (StreamWriter sw = file.CreateText()) + { + foreach(var line in lines) + { + if(!line.Split('|')[0].Equals(key)) + { + sw.WriteLine(line); + } + } + } + } + + public void clear() + { + dictA.Clear(); + + //Clearing the file + using (StreamWriter sw = file.CreateText()) + { + + } + } + + public Dictionary getDictionary() + { + return dictA; + } + + public void Delete() + { + file.Delete(); + } + + public void MoveTo(string path) + { + file.MoveTo(path); + } + + public void CopyTo(string path) + { + file.CopyTo(path); + } + } + + //A File to save lists + public class ListFile + { + //a file to store some lists in + + private FileInfo file; + private List listA; + private const string extension = ".lst"; + + public ListFile(string name) + { + listA = new List(); + createListFile(name, "Data"); + } + + public ListFile(string name, string directory) + { + listA = new List(); + createListFile(name, directory); + } + + private void createListFile(string name, string directory) + { + //saving in standard directory 'Data' + if (!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + var fn = directory + "/" + name; + + //adding the extension .list if not existing + if (!name.Contains(extension)) + { + fn += extension; + } + + file = new FileInfo(fn); + //reading the file if existent + + if (file.Exists) + { + readFile(); + } + else + { + using (StreamWriter sw = file.CreateText()) + { + + } + } + } + + public void readFile() + { + //clearing the list to prevent doubled items + listA.Clear(); + //reading the file line by line to list + + foreach (var line in File.ReadAllLines(file.FullName)) + { + listA.Add(line); + } + } + + public void add(string item) + { + //first appending item to list, then writing it to file + listA.Add(item); + + using (StreamWriter sw = file.AppendText()) + { + sw.WriteLine(item); + } + } + + public void remove(int id) + { + listA.RemoveAt(id); + var cId = 0; + //getting the lines of the file + var lines = File.ReadAllLines(file.FullName); + + //writing and skipping the line with the named id + using (StreamWriter sw = file.AppendText()) + { + foreach (var line in lines) + { + if (cId != id) + { + sw.WriteLine(line); + } + cId++; + } + } + } + + public void clear() + { + //clearing list and overwriting file + listA.Clear(); + + using (StreamWriter sw = file.CreateText()) + { + + } + } + + public List getList() + { + return listA; + } + + public void Delete() + { + file.Delete(); + } + + public void MoveTo(string destFileName) + { + file.MoveTo(destFileName); + } + + public void CopyTo(string destFileName) + { + file.CopyTo(destFileName); + } + } + + //The standard Logfile + public class LogFile + { + public FileInfo logfile; + public bool withTime = true; + public string timestring = "HH:mm:ss"; + + string executable; + + public LogFile() + { + //choosing the name of the current executable as logfilename + executable = System.AppDomain.CurrentDomain.FriendlyName; + logfile = new FileInfo(executable.Replace(".exe", "") + ".log"); + } + + public LogFile(string path) + { + //logfile with chosen path + logfile = new FileInfo(path); + } + + private void writeLogStart() + { + //creating or overwriting the logfile and writing the head + using (StreamWriter sw = logfile.CreateText()) + { + sw.WriteLine("Started logging at " + DateTime.Now.ToString(@"YYYY/MM/DD_HH:mm:ss") + " with executable " + executable); + } + } + + public void log(string data) + { + //the user decides whether he wants a the datetimestring or not + using (StreamWriter sw = logfile.AppendText()) + { + if (withTime) + { + sw.WriteLine(DateTime.Now.ToString(timestring) + ": " + data); + } + else + { + sw.WriteLine(data); + } + } + } + + public void dump(string path) + { + //storing the file in the given path + try + { + logfile.MoveTo(path); + } + catch { log("{Gaia.Logging} [!!] Failed moving this file"); } + } + + public void dump() + { + //storing the file in directory Logs + if (!Directory.Exists("Logs")) + { + Directory.CreateDirectory("Logs"); + } + + int count = 1; + string filename = "Logs/" + DateTime.Now.ToString("YY-MM-DD"); + + //counting in the filename while the file would overwrite an older one + while (File.Exists(filename + ".log")) + { + filename.Replace("_" + count, ""); + count++; + filename += "_" + count; + } + + try + { + logfile.MoveTo(filename + ".log"); + } + catch { log("{Gaia.Logging} [!!] Failed moving this file"); } + } + } + + public class XMLDictionaryFile + { + private XmlDocument document; + private FileInfo file; + const string extension = ".dix"; + + public XMLDictionaryFile(string name) + { + createFile(name, "Data/"); + } + + public XMLDictionaryFile(string name, string directory) + { + createFile(name, directory); + } + + private void createFile(string name, string directory) + { + document = new XmlDocument(); + + if(!Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + if (!name.Contains(".dix")) + { + name += extension; + } + + name = directory+"/" + name; + + file = new FileInfo(name); + + if (file.Exists) + { + document.Load(file.FullName); + } + else + { + XmlElement meta = document.CreateElement("meta"); + meta.SetAttribute("creator", AppDomain.CurrentDomain.FriendlyName); + meta.SetAttribute("creationtime", DateTime.Now.ToString()); + } + + save(); + } + + private void save() + { + document.Save(file.FullName); + } + + public void append(string key,string value) + { + XmlElement keyElement = document.CreateElement(key); + keyElement.InnerText = value; + save(); + } + + public void append(string key, XmlElement value) + { + document.CreateElement(key).InnerXml = value.OuterXml; + save(); + } + + public void append(string key, string value, Dictionary attributes) + { + var keyElement = document.CreateElement(key); + keyElement.InnerText = value; + + foreach(var attribute in attributes) + { + keyElement.SetAttribute(attribute.Key,attribute.Value); + } + save(); + } + } + } +} diff --git a/Gaia/Gaia.csproj b/Gaia/Gaia.csproj new file mode 100644 index 0000000..c6c40ed --- /dev/null +++ b/Gaia/Gaia.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {0E9767EC-BD0D-4251-8A81-CA79B3A3DC58} + Library + Properties + GAIA + G.A.I.A + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + false + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/Gaia/Properties/AssemblyInfo.cs b/Gaia/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cd4be5f --- /dev/null +++ b/Gaia/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("G.A.I.A")] +[assembly: AssemblyDescription("Generally Advanced IO Additions")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Trivernis Software")] +[assembly: AssemblyProduct("G.A.I.A.")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("Trivernis Software")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("0e9767ec-bd0d-4251-8a81-ca79b3a3dc58")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Gaia/Properties/Resources.Designer.cs b/Gaia/Properties/Resources.Designer.cs new file mode 100644 index 0000000..f589f6b --- /dev/null +++ b/Gaia/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace GAIA.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GAIA.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Gaia/Properties/Resources.resx b/Gaia/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Gaia/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file