コード例 #1
0
ファイル: Archive.cs プロジェクト: jenden0/KOS
        /// <summary>
        /// Get the file from the OS.
        /// </summary>
        /// <param name="name">filename to look for</param>
        /// <param name="ksmDefault">if true, it prefers to use the KSM filename over the KS.  The default is to prefer KS.</param>
        /// <returns>the full fileinfo of the filename if found</returns>
        private System.IO.FileInfo FileSearch(string name, bool ksmDefault = false)
        {
            var path = ArchiveFolder + name;

            if (Path.HasExtension(path))
            {
                return(File.Exists(path) ? new System.IO.FileInfo(path) : null);
            }
            var kerboscriptFile = new System.IO.FileInfo(PersistenceUtilities.CookedFilename(path, KERBOSCRIPT_EXTENSION, true));
            var kosMlFile       = new System.IO.FileInfo(PersistenceUtilities.CookedFilename(path, KOS_MACHINELANGUAGE_EXTENSION, true));

            if (kerboscriptFile.Exists && kosMlFile.Exists)
            {
                return(ksmDefault ? kosMlFile : kerboscriptFile);
            }
            if (kerboscriptFile.Exists)
            {
                return(kerboscriptFile);
            }
            if (kosMlFile.Exists)
            {
                return(kosMlFile);
            }
            return(null);
        }
コード例 #2
0
ファイル: Archive.cs プロジェクト: jenden0/KOS
        public override void AppendToFile(string name, byte[] bytesToAppend)
        {
            SafeHouse.Logger.SuperVerbose("Archive: AppendToFile: " + name);
            System.IO.FileInfo info = FileSearch(name);

            string fullPath = info == null?string.Format("{0}{1}", ArchiveFolder, PersistenceUtilities.CookedFilename(name, KERBOSCRIPT_EXTENSION, true)) : info.FullName;

            // Deliberately not catching potential I/O exceptions from this, so they will percolate upward and be seen by the user:
            using (var outfile = new BinaryWriter(File.Open(fullPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)))
            {
                outfile.Write(bytesToAppend);
            }
        }
コード例 #3
0
ファイル: Archive.cs プロジェクト: jenden0/KOS
        public override void AppendToFile(string name, string textToAppend)
        {
            SafeHouse.Logger.SuperVerbose("Archive: AppendToFile: " + name);
            System.IO.FileInfo info = FileSearch(name);

            string fullPath = info == null?string.Format("{0}{1}", ArchiveFolder, PersistenceUtilities.CookedFilename(name, KERBOSCRIPT_EXTENSION, true)) : info.FullName;

            // Using binary writer so we can bypass the OS behavior about ASCII end-of-lines and always use \n's no matter the OS:
            // Deliberately not catching potential I/O exceptions from this, so they will percolate upward and be seen by the user:
            using (var outfile = new BinaryWriter(File.Open(fullPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)))
            {
                byte[] binaryLine = System.Text.Encoding.UTF8.GetBytes((textToAppend + "\n").ToCharArray());
                outfile.Write(binaryLine);
            }
        }
コード例 #4
0
ファイル: Archive.cs プロジェクト: Whitecaribou/KOS
        /// <summary>
        /// Get the file from the OS.
        /// </summary>
        /// <param name="name">filename to look for</param>
        /// <param name="ksmDefault">if true, it prefers to use the KSM filename over the KS.  The default is to prefer KS.</param>
        /// <returns>the full fileinfo of the filename if found</returns>
        private System.IO.FileInfo FileSearch(string name, bool ksmDefault = false)
        {
            var path = ArchiveFolder + name;
            if (Path.HasExtension(path))
            {
                return File.Exists(path) ? new System.IO.FileInfo(path) : null;
            }
            var kerboscriptFile = new System.IO.FileInfo(PersistenceUtilities.CookedFilename(path, KERBOSCRIPT_EXTENSION, true));
            var kosMlFile = new System.IO.FileInfo(PersistenceUtilities.CookedFilename(path, KOS_MACHINELANGUAGE_EXTENSION, true));

            if (kerboscriptFile.Exists && kosMlFile.Exists)
            {
                return ksmDefault ? kosMlFile : kerboscriptFile;
            }
            if (kerboscriptFile.Exists)
            {
                return kerboscriptFile;
            }
            if (kosMlFile.Exists)
            {
                return kosMlFile;
            }
            return null;
        }