Exemplo n.º 1
0
        public static SrcFile ShouldBeFilled(this SrcFile srcFile)
        {
            srcFile.ShouldNotBeNull();
            srcFile.path.ShouldNotBeNull();
            srcFile.links.ShouldBeFilled();
            srcFile.commit.ShouldBeFilled();
            srcFile.attributes.ShouldNotBeNull();
            srcFile.size.ShouldBeGreaterThanOrEqualTo(0);
            srcFile.mimetype.CouldBeNull();

            return(srcFile);
        }
Exemplo n.º 2
0
 private static void CopyDirectory(DirectoryInfo sourceDir, DirectoryInfo destDir)
 {
     if (!destDir.Exists)
     {
         destDir.Create();
     }
     FileInfo[] SrcFiles = sourceDir.GetFiles();
     foreach (FileInfo SrcFile in SrcFiles)
     {
         SrcFile.CopyTo(Path.Combine(destDir.FullName, SrcFile.Name));
     }
     DirectoryInfo[] SrcDirectories = sourceDir.GetDirectories();
     foreach (DirectoryInfo SrcDirectory in SrcDirectories)
     {
         CopyDirectory(SrcDirectory, new DirectoryInfo(Path.Combine(destDir.FullName, SrcDirectory.Name)));
     }
 }
Exemplo n.º 3
0
        public void GetScriptsTest()
        {
            var scripts = new SrcFile(@"srcTest\scripts.src")
                          .GetScripts()
                          .Select(x => x.ToLower())
                          .ToList();

            Assert.AreEqual(scripts[0], @"srctest\script.d");
            Assert.AreEqual(scripts[1], @"srctest\system\script1.d");
            Assert.AreEqual(scripts[2], @"srctest\system\script2.d");
            Assert.AreEqual(scripts[3], @"srctest\system\script3.d");
            Assert.AreEqual(scripts[4], @"srctest\content\script.d");
            Assert.AreEqual(scripts[5], @"srctest\content\dialogs\npc_1.d");
            Assert.AreEqual(scripts[6], @"srctest\content\dialogs\npc_2.d");
            Assert.AreEqual(scripts[7], @"srctest\content\dialogs\npc_3.d");
            Assert.AreEqual(scripts[8], @"srctest\content\dialogs\npc_4.d");
            Assert.AreEqual(scripts[9], @"srctest\content\dialogs\npc_5.d");
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        private static void UpgradeSettings()
        {
            if (Settings.LastUpgradeVersion == 0)
            {
                // Server port was modified on this version due to protocal differences.
                if (Settings.ServerPort == 12341)
                {
                    Settings.ServerPort = 12340;
                }
            }

            if (Settings.LastUpgradeVersion < 100000612)
            {
                // Copy over manifests folder from old storage path.
                string SrcPath = Path.Combine(Settings.StoragePath, "Manifests");
                string DstPath = Path.Combine(AppDataDir, "Manifests");
                if (Directory.Exists(SrcPath))
                {
                    if (!Directory.Exists(DstPath))
                    {
                        Directory.CreateDirectory(DstPath);
                    }

                    foreach (string SrcFile in Directory.GetFiles(SrcPath))
                    {
                        string DstFile = Path.Combine(DstPath, SrcFile.Substring(SrcPath.Length + 1));
                        if (!File.Exists(DstFile))
                        {
                            File.Copy(SrcFile, DstFile);
                        }
                    }
                }

                // Storage settings need to use old paths.
                if (Settings.StoragePath.Length > 0)
                {
                    Settings.StorageLocations.Add(new StorageLocation {
                        Path = Settings.StoragePath, MaxSize = Settings.StorageMaxSize
                    });
                }
            }

            Settings.LastUpgradeVersion = AppVersion.VersionNumber;
        }
Exemplo n.º 5
0
        /// <summary>
        /// </summary>
        private static void InitSettings()
        {
            string AppDir = AppDataDir;

            SettingsPath = Path.Combine(AppDir, "Config.json");
            SettingsBase.Load(SettingsPath, out Settings);

            if (Settings.LastUpgradeVersion < AppVersion.VersionNumber)
            {
                Logger.Log(LogLevel.Info, LogCategory.Main, "InitSettings: Upgrading settings.");
                UpgradeSettings();
            }

            if (Settings.LastUpgradeVersion < 100000613)
            {
                // Copy over manifests folder from old storage path.
                string SrcPath = Path.Combine(Settings.StoragePath, "Manifests");
                string DstPath = Path.Combine(AppDataDir, "Manifests");
                if (Directory.Exists(SrcPath))
                {
                    if (!Directory.Exists(DstPath))
                    {
                        Directory.CreateDirectory(DstPath);
                    }

                    foreach (string SrcFile in Directory.GetFiles(SrcPath))
                    {
                        string DstFile = Path.Combine(DstPath, SrcFile.Substring(SrcPath.Length + 1));
                        if (!File.Exists(DstFile))
                        {
                            File.Copy(SrcFile, DstFile);
                        }
                    }
                }
            }

            Settings.Save(SettingsPath);

            ApplySettings();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Extracts the file from the gzip archive.
        /// </summary>
        protected override void ExecuteTask()
        {
            try {
                using (GZipInputStream gzs = new GZipInputStream(SrcFile.OpenRead())) {
                    Log(Level.Info, "Expanding '{0}' to '{1}' ({2} bytes).",
                        SrcFile.FullName, DestFile.FullName, gzs.Length);

                    // holds data from src file
                    byte[] data = new byte[8 * 1024];

                    // first read from input to ensure we're dealing with valid
                    // src file before we actually create the dest file
                    int size = gzs.Read(data, 0, data.Length);

                    // write expanded data to dest file
                    using (FileStream fs = new FileStream(DestFile.FullName, FileMode.Create, FileAccess.Write, FileShare.None)) {
                        while (size > 0)
                        {
                            fs.Write(data, 0, size);
                            size = gzs.Read(data, 0, data.Length);
                        }
                        // close output stream
                        fs.Close();
                    }
                    // close input stream
                    gzs.Close();
                }
            } catch (IOException ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Failed to expand '{0}' to '{1}'.", SrcFile.FullName,
                                                       DestFile.FullName), Location, ex);

                /* Uncomment when upgrade to next #ziplib release is done
                 * } catch (GZipException ex) {
                 *  throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                 *      "Invalid gzip file '{0}'.", SrcFile.FullName), Location, ex);
                 */
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Extracts the files from the archive.
        /// </summary>
        protected override void ExecuteTask()
        {
            Stream fs       = null;
            Stream instream = null;

            try {
                // ensure archive exists
                if (!SrcFile.Exists)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Tar file '{0}' does not exist.", SrcFile.FullName),
                                             Location);
                }

                fs = SrcFile.OpenRead();

                // wrap inputstream with corresponding compression method
                switch (CompressionMethod)
                {
                case TarCompressionMethod.GZip:
                    instream = new GZipInputStream(fs);
                    break;

                case TarCompressionMethod.BZip2:
                    instream = new BZip2InputStream(fs);
                    break;

                default:
                    instream = fs;
                    break;
                }

                using (TarInputStream s = new TarInputStream(instream)) {
                    Log(Level.Info, "Expanding '{0}' to '{1}'.",
                        SrcFile.FullName, DestinationDirectory.FullName);

                    TarEntry entry;

                    // extract the file or directory entry
                    while ((entry = s.GetNextEntry()) != null)
                    {
                        if (entry.IsDirectory)
                        {
                            ExtractDirectory(s, DestinationDirectory.FullName,
                                             entry.Name, entry.ModTime);
                        }
                        else
                        {
                            ExtractFile(s, DestinationDirectory.FullName,
                                        entry.Name, entry.ModTime, entry.Size);
                        }
                    }
                }
            } catch (IOException ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Failed to expand '{0}' to '{1}'.", SrcFile.FullName,
                                                       DestinationDirectory.FullName), Location, ex);
            } catch (TarException ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Invalid tar file '{0}'.", SrcFile.FullName), Location, ex);
            } catch (BZip2Exception ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Invalid bzip2'd tar file '{0}'.", SrcFile.FullName), Location, ex);
            } catch (GZipException ex) {
                throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                       "Invalid gzipped tar file '{0}'.", SrcFile.FullName), Location, ex);
            } finally {
                // close the filestream
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Exemplo n.º 8
0
        //------------------------------------------------------------
        // コンストラクタ。
        Compiler(string aSrcListFilePath, string aOutputDirPath)
        {
            // 初期化
            mErrorList = new List <CompileError>();
            mIsSuccess = false;

            // ソースファイルリストをオープン
            string[] srcFilePathList = null;
            try
            {
                srcFilePathList = System.IO.File.ReadAllLines(aSrcListFilePath);
            }
            catch (Exception)
            {
                System.Console.Error.WriteLine("'" + aSrcListFilePath + "'を読み込めませんでした。");
                return;
            }

            // シンボルツリーを作成
            SymbolTree symbolTree = new SymbolTree();

            // 各ソースファイルのRead,Lexer,Parserを実行
            // todo: マルチスレッド対応。
            List <SrcFile> srcFiles = new List <SrcFile>();

            foreach (var srcFilePath in srcFilePathList)
            {
                // SrcFile作成
                SrcFile srcFile = null;
                {
                    string srcFileText = null;
                    try
                    {
                        srcFileText = System.IO.File.ReadAllText(srcFilePath);
                    }
                    catch (Exception)
                    {
                        // コンパイルエラー情報を作成
                        mErrorList.Add(new CompileError(
                                           CompileErrorKind.SYSTEM_CANT_OPEN_SRC_FILE
                                           , "'" + srcFilePath + "'を読み込めませんでした。"
                                           ));

                        // 次のソースへ
                        continue;
                    }
                    srcFile = new SrcFile(srcFilePath, srcFileText);
                }

                // Lexer
                var lexer = new Lexer(srcFile.Text);
                if (lexer.IsError())
                {
                    // todo:
                    // コンパイルエラー情報を作成

                    // 次のソースへ。
                    continue;
                }

                // Parser
                var parser = new Parser(lexer);
                if (parser.GetErrorKind() != Parser.ErrorKind.NONE)
                {
                    // todo:
                    // コンパイルエラー情報を作成

                    // 次のソースへ。
                    continue;
                }

                // Add to SymbolTree
                if (!symbolTree.Add(parser.ModuleContext))
                {
                    // todo:
                    // コンパイルエラー情報を作成

                    // 次のソースへ
                    continue;
                }
            }

            // エラーが発生していたら出力して中断
            if (mErrorList.Count != 0)
            {
                dumpError();
                return;
            }

            // 展開
            // todo: マルチスレッド対応
            if (!symbolTree.Expand())
            {
                // todo:
                // コンパイルエラー情報を作成

                // 終了
                return;
            }

            // ファイル出力
            symbolTree.WriteToXML(aOutputDirPath);

            // 問題なく終了
            mIsSuccess = true;
        }
Exemplo n.º 9
0
 public SrcEntry(SrcFile srcFile)
 {
     Src     = srcFile;
     SrcFile = srcFile;
 }