Example #1
0
        private void Main2(ArgsReader ar)
        {
            string rFile = ar.NextArg();
            string wFile = ar.NextArg();

            new HtmlConverter().ToOneHtml(rFile, wFile);
        }
Example #2
0
        private void Main2(ArgsReader ar)
        {
            string        resDir    = null;
            List <string> srcDirs   = new List <string>();
            string        outJSFile = null;

            JSModuleConverter mc = new JSModuleConverter();

            while (true)
            {
                if (ar.ArgIs("/R"))
                {
                    resDir = ar.NextArg();
                    continue;
                }
                if (ar.ArgIs("/S"))
                {
                    srcDirs.Add(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/W"))
                {
                    outJSFile = ar.NextArg();
                    continue;
                }
                if (ar.HasArgs())
                {
                    throw new Exception("不明なコマンド引数");
                }

                break;
            }

            if (resDir == null)
            {
                throw new Exception("リソースディレクトリを指定して下さい。");
            }

            if (srcDirs.Count == 0)
            {
                throw new Exception("ソースディレクトリを指定して下さい。");
            }

            if (outJSFile == null)
            {
                throw new Exception("出力JSファイルを指定して下さい。");
            }

            mc.LoadResourceDir(resDir);

            foreach (string srcDir in srcDirs)
            {
                mc.LoadSourceDir(srcDir);
            }

            mc.WriteJSFile(outJSFile);
        }
Example #3
0
        private void Main2(ArgsReader ar)
        {
            try
            {
                string rFile = ar.NextArg();
                string wFile = ar.NextArg();

                FileTools.Delete(wFile);

                try
                {
                    // ---- FreeImage ここから

                    if (FreeImage.IsAvailable() == false)
                    {
                        throw new Exception("no FreeImage.dll");
                    }

                    FIBITMAP dib = FreeImage.LoadEx(rFile);

                    if (dib.IsNull)
                    {
                        throw new Exception("Failed load image");
                    }

                    FreeImage.SaveEx(ref dib, wFile, false);
                    FreeImage.UnloadEx(ref dib);

                    // ---- FreeImage ここまで
                }
                catch
                {
                    FileTools.Delete(wFile);
                    throw;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #4
0
        private void Main3(ArgsReader ar)
        {
            try
            {
                if (ar.NextArg() != "CS-Conv")
                {
                    throw new Exception("不正なコールサイン");
                }

                string inputDir            = StringTools.LiteDecode(ar.NextArg());
                string outputDir           = StringTools.LiteDecode(ar.NextArg());
                bool   outputOverwriteMode = int.Parse(ar.NextArg()) != 0;
                string successfulFile      = ar.NextArg();

                new ConvMain().Perform(inputDir, outputDir, outputOverwriteMode, successfulFile);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #5
0
        private void Main2(ArgsReader ar)
        {
            string        resDir    = null;
            List <string> srcDirs   = new List <string>();
            string        outJSFile = null;
            string        tagsFile  = null;

            while (true)
            {
                if (ar.ArgIs("/R"))
                {
                    resDir = ar.NextArg();
                    continue;
                }
                if (ar.ArgIs("/S"))
                {
                    srcDirs.Add(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/WB"))
                {
                    outJSFile  = ar.NextArg();
                    outJSFile  = FileTools.MakeFullPath(outJSFile);
                    outJSFile += ".js";
                    continue;
                }
                if (ar.ArgIs("/T"))
                {
                    tagsFile = ar.NextArg();
                    continue;
                }
                if (ar.HasArgs())
                {
                    throw new Exception("不明なコマンド引数");
                }

                break;
            }

            if (resDir == null)
            {
                throw new Exception("リソースディレクトリを指定して下さい。");
            }

            if (srcDirs.Count == 0)
            {
                throw new Exception("ソースディレクトリを指定して下さい。");
            }

            if (outJSFile == null)
            {
                throw new Exception("出力JSファイルを指定して下さい。");
            }

            if (tagsFile == null)
            {
                throw new Exception("tagsファイルを指定して下さい。");
            }

            {
                JSModuleConverter mc = new JSModuleConverter();

                mc.LoadResourceDir(resDir);

                foreach (string srcDir in srcDirs)
                {
                    mc.LoadSourceDir(srcDir);
                }

                mc.WriteJSFile(outJSFile);
            }

            using (WorkingDir wd = new WorkingDir())
            {
                const string MID_TAGS_FILE = "tags.mid.tmp";

                ProcessTools.Batch(new string[]
                {
                    string.Format(@"C:\Factory\DevTools\makeTags.exe /JS {0} {1}", outJSFile, MID_TAGS_FILE),
                },
                                   wd.GetPath(".")
                                   );

                if (File.Exists(wd.GetPath(MID_TAGS_FILE)) == false)
                {
                    throw new Exception("tagsファイルの生成に失敗しました。");
                }

                string[] tagsLines = File.ReadAllLines(wd.GetPath(MID_TAGS_FILE), StringTools.ENCODING_SJIS);

                File.AppendAllLines(tagsFile, tagsLines, StringTools.ENCODING_SJIS);                 // 注意:追記する。
            }
        }
Example #6
0
        private void Main3(ArgsReader ar)
        {
            Console.WriteLine("Prime4096_MillerRabin_K: " + Ground.MillerRabin_K);             // test

            if (ar.ArgIs("/S"))
            {
                Ground.Stop();
                return;
            }
            if (ar.ArgIs("/P"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("IsPrime_sn: " + sn);

                File.WriteAllText(outFile, PrimeUtils.IsPrime(Common.ToBigInteger(sn)) ? "P" : "N", Encoding.ASCII);
                return;
            }
            if (ar.ArgIs("/F"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("Factorization_sn: " + sn);

                FactorizationUtils.Factorization(Common.ToBigInteger(sn), outFile);
                return;
            }
            if (ar.ArgIs("/L"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("GetLowerPrime_sn: " + sn);

                File.WriteAllText(outFile, Common.ToString(
                                      GetLowerPrime(
                                          Common.ToBigInteger(sn)
                                          )
                                      ),
                                  Encoding.ASCII
                                  );
                return;
            }
            if (ar.ArgIs("/H"))
            {
                string sn      = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("GetHigherPrime_sn: " + sn);

                File.WriteAllText(outFile, Common.ToString(
                                      GetHigherPrime(
                                          Common.ToBigInteger(sn)
                                          )
                                      ),
                                  Encoding.ASCII
                                  );
                return;
            }
            if (ar.ArgIs("/R"))
            {
                string sn1     = ar.NextArg();
                string sn2     = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("FindPrimes_sn1: " + sn1);
                Console.WriteLine("FindPrimes_sn2: " + sn2);

                FindPrimesUtils.FindPrimes(
                    Common.ToBigInteger(sn1),
                    Common.ToBigInteger(sn2),
                    outFile
                    );
                return;
            }
            if (ar.ArgIs("/C"))
            {
                string sn1     = ar.NextArg();
                string sn2     = ar.NextArg();
                string outFile = ar.NextArg();

                Console.WriteLine("GetPrimeCount_sn1: " + sn1);
                Console.WriteLine("GetPrimeCount_sn2: " + sn2);

                File.WriteAllText(outFile, Common.ToString(
                                      FindPrimesUtils.GetPrimeCount(
                                          Common.ToBigInteger(sn1),
                                          Common.ToBigInteger(sn2)
                                          )
                                      ),
                                  Encoding.ASCII
                                  );
                return;
            }
            throw new ArgumentException("不明なコマンド引数");
        }
Example #7
0
        private void Main2(ArgsReader ar)
        {
            while (true)
            {
                if (ar.ArgIs("/WD"))
                {
                    Ground.I.WorkDir = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/FFMD"))
                {
                    Ground.I.ffmpegDir = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/ITF"))
                {
                    Ground.I.ImgToolsFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/BCF"))
                {
                    Ground.I.BmpToCsvFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/MST-F"))
                {
                    Ground.I.MasterFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/AF"))
                {
                    Ground.I.AudioFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/IF"))
                {
                    Ground.I.ImageFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/MF"))
                {
                    Ground.I.MovieFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/FPS"))
                {
                    Ground.I.FramePerSecond = int.Parse(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/JQ"))
                {
                    Ground.I.JpegQuality = int.Parse(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/EMF"))
                {
                    Ground.I.ErrorMessageFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/LF"))
                {
                    Ground.I.LogFile = CommonUtils.Decode(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/AG"))
                {
                    Ground.I.ApproveGuest = int.Parse(ar.NextArg()) != 0;
                    continue;
                }
                if (ar.ArgIs("/DI"))
                {
                    Ground.I.画像を二重に表示 = int.Parse(ar.NextArg()) != 0;
                    continue;
                }
                if (ar.ArgIs("/DI-W"))
                {
                    Ground.I.画像を二重に表示_MonitorW = int.Parse(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/DI-H"))
                {
                    Ground.I.画像を二重に表示_MonitorH = int.Parse(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/DI-B"))
                {
                    Ground.I.画像を二重に表示_ぼかし = int.Parse(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/DI-A"))
                {
                    Ground.I.画像を二重に表示_明るさ = int.Parse(ar.NextArg());
                    continue;
                }
                if (ar.ArgIs("/M"))
                {
                    Ground.I.MasteringFlag = int.Parse(ar.NextArg()) != 0;
                    continue;
                }
                break;
            }
            if (ar.HasArgs())
            {
                throw new Exception("不明なコマンド引数");
            }

            FileTools.Delete(Ground.I.MovieFile);
            FileTools.Delete(Ground.I.ErrorMessageFile);
            FileTools.Delete(Ground.I.LogFile);

            ProcMain.WriteLog = message =>
            {
                try
                {
                    using (new MSection("{d49cc1ff-9c18-4ad9-9a3e-24795d4c14d5}"))                     // 念の為ロック
                    {
                        using (StreamWriter writer = new StreamWriter(Ground.I.LogFile, true, Encoding.UTF8))
                        {
                            writer.WriteLine("[" + DateTime.Now + "] " + message);
                        }
                    }
                }
                catch
                { }
            };

            try
            {
                ProcMain.WriteLog("<<<< Converter START >>>>");

                new Converter().Main();

                ProcMain.WriteLog("<<<< Converter END >>>>");
            }
            catch (Exception e)
            {
                ProcMain.WriteLog(e);

                File.WriteAllText(Ground.I.ErrorMessageFile, e.Message, Encoding.UTF8);
            }
        }
Example #8
0
		public void Main(ArgsReader ar)
		{
			int portNo = 80;
			DocRoot docRoot = new DocRoot();
			MIMEType mimeType = new MIMEType();

			if (ar.HasArgs())
				portNo = int.Parse(ar.NextArg());

			portNo = IntTools.ToRange(portNo, 1, 65535);

			while (ar.HasArgs())
				docRoot.AddRootDir(ar.NextArg());

			HTTPServerChannel.RequestTimeoutMillis = 30000; // 30 sec
			HTTPServerChannel.ResponseTimeoutMillis = 2 * 86400000; // 2 day
			//HTTPServerChannel.FirstLineTimeoutMillis = 2000; // 2 sec == def
			HTTPServerChannel.IdleTimeoutMillis = 10000; // 10 sec
			HTTPServerChannel.BodySizeMax = 2000000; // 2 MB
			HTTPServerChannel.BuffSize = 500000; // 500 KB

			JsonTools.DecodeStringFilter = v => JString.ToJString(v, true, true, true, true);
			JsonTools.DecodeNestingLevelMax = 30;
			JsonTools.DecodeObjectCountMax = 1000;

			HTTPServer hs = new HTTPServer()
			{
				PortNo = portNo,
				//Backlog = 100, // == def
				//ConnectMax = 30, // == def

				Interlude = () =>
				{
					return Console.KeyAvailable == false;
				},

				HTTPConnected = channel =>
				{
					string method = channel.Method;
					string path = channel.Path;

					HTTPRequest hr = new HTTPRequest();

					hr.IP = channel.Channel.Handler.RemoteEndPoint.ToString(); // TODO
					hr.Method = JString.ToJString(channel.Method, false, false, false, false); // 正規化
					hr.URLPath = JString.ToJString(channel.Path, true, false, false, true); // 正規化

					// HACK ??? ParsePathQuery より前に DecodeURL しているのでクエリに '?', '&', '=' を使えない???

					ParsePathQuery(hr);

					// 特別な処理:アスタリスクの直前までをパスと見なす。
					{
						int i = hr.Path.IndexOf('*');

						if (i != -1)
							hr.Path = hr.Path.Substring(0, i);
					}

					if (hr.Path[hr.Path.Length - 1] == '/')
						hr.Path += "index.html";

					hr.Path = CommonUtils.GetFairRelPath(hr.Path);
					hr.HTTP_Version = JString.ToJString(channel.HTTPVersion, false, false, false, false); // 正規化

					foreach (string[] headerPair in channel.HeaderPairs)
					{
						hr.HeaderPairs.Add(
							JString.ToJString(headerPair[0], true, false, false, true), // 正規化
							JString.ToJString(headerPair[1], true, false, false, true)  // 正規化
							);
					}

					if (hr.Method == "GET")
					{
						hr.Json = null;
					}
					else if (method == "POST")
					{
						hr.Json = JsonTools.Decode(channel.Body); // 正規化
					}
					else
					{
						throw new Exception("不明なメソッド");
					}

					// HACK ??? フォルダの場合の 301 対応

					string targetFile = docRoot.GetRootDirs().Select(v => Path.Combine(v, hr.Path)).FirstOrDefault(v => File.Exists(v));

					if (targetFile == null)
					{
						channel.ResStatus = 404;
					}
					else
					{
						if (StringTools.EndsWithIgnoreCase(targetFile, ".alt.txt"))
						{
							string intervateClassName = File.ReadAllLines(targetFile, Encoding.ASCII)[0];
							Type intervateClass = Type.GetType(intervateClassName + "," + Assembly.GetEntryAssembly().GetName().Name);
							ReflectTools.MethodUnit intervateCtor = ReflectTools.GetConstructor(intervateClass);
							IService service = (IService)intervateCtor.Construct(new object[0]);

							object ret = service.Perform(hr, ref targetFile);

							if (ret != null)
							{
								string sRet = JsonTools.Encode(ObjectTree.Conv(ret));
								byte[] resBody = Encoding.UTF8.GetBytes(sRet);

								channel.ResStatus = 200;
								channel.ResBody_B = resBody;
								channel.ResContentType = "application/json";

								goto endSetResponse;
							}
						}
						channel.ResStatus = 200;

						if (new FileInfo(targetFile).Length <= 2000000)
							channel.ResBody_B = File.ReadAllBytes(targetFile);
						else
							channel.ResBody = ResponseFileReader(targetFile);

						channel.ResContentType = mimeType.FileToContentType(targetFile);

					endSetResponse:
						;
					}
				},
			};

			ProcMain.WriteLog("Server Started");

			hs.Perform();

			ProcMain.WriteLog("Server Ended");
		}
Example #9
0
        private void Main3(ArgsReader ar)
        {
            bool noOpenOutput = ar.ArgIs("/-D");

            if (ar.HasArgs(2))
            {
                throw new Exception("不明なコマンド引数");
            }

            if (ar.HasArgs())
            {
                Ground.RootDir = FileTools.MakeFullPath(ar.NextArg());
            }
            else
            {
                Ground.RootDir = CommonUtils.GetRiotDir();
            }
            Console.WriteLine("RootDir: " + Ground.RootDir);

            if (Directory.Exists(Ground.RootDir) == false)
            {
                throw new Exception("no RootDir");
            }

            Ground.FileAndDirectoryConfigFile = Path.Combine(Ground.RootDir, "FileAndDirectory.config.txt");
            Ground.ResourceDir                 = Path.Combine(Ground.RootDir, "res");
            Ground.OutDir                      = Path.Combine(Ground.RootDir, "out");
            Ground.OutHtmlFile                 = Path.Combine(Ground.OutDir, "index.html");
            Ground.OutHtmlFile_Slimmed         = Path.Combine(Ground.OutDir, "slimmed_index.html");
            Ground.OutHtmlFile_Slimmed_Wrapped = Path.Combine(Ground.OutDir, "slimmed_wrapped_index.html");
            Ground.OutTestMainHtmlFileBase     = Path.Combine(Ground.OutDir, "index_");

            Console.WriteLine("ComponentAndScriptConfigFile: " + Ground.FileAndDirectoryConfigFile);
            Console.WriteLine("ResourceDir: " + Ground.ResourceDir);
            Console.WriteLine("OutDir: " + Ground.OutDir);
            Console.WriteLine("OutHtmlFile: " + Ground.OutHtmlFile);
            Console.WriteLine("OutHtmlFile_Slimmed: " + Ground.OutHtmlFile_Slimmed);
            Console.WriteLine("OutTestMainHtmlFileBase: " + Ground.OutTestMainHtmlFileBase);

            // ---- check ----

            if (File.Exists(Ground.FileAndDirectoryConfigFile) == false)
            {
                throw new Exception("no FileAndDirectoryConfigFile");
            }

            if (Directory.Exists(Ground.ResourceDir) == false)
            {
                throw new Exception("no ResourceDir");
            }

            if (Directory.Exists(Ground.OutDir) == false)
            {
                throw new Exception("no OutDir");
            }

            //Ground.OutHtmlFile
            //Ground.OutTestMainHtmlFileBase

            // ----

            this.LoadFileAndDirectoryConfig();

            Ground.DefineManager    = new DefineManager();          // 先に!
            Ground.ScriptManager    = new ScriptManager();
            Ground.ComponentManager = new ComponentManager();
            Ground.MainHtmlText     = File.ReadAllText(Ground.MainHtmlFile, StringTools.ENCODING_SJIS);
            Ground.GlobalName       = Ground.DefineManager.GetPropertyNN("GLOBAL");

            FileTools.CleanupDir(Ground.OutDir);
            FileTools.CopyDir(Ground.ResourceDir, Ground.OutDir);

            foreach (string dir in Ground.ComponentAndScriptDirs)
            {
                this.CopyResources(dir, Ground.OutDir);
            }

            {
                string TESTMAIN_PTN  = Guid.NewGuid().ToString("B");
                string outHtmlFormat = Ground.MainHtmlText;

                GlobalIdentifierResolver gir = new GlobalIdentifierResolver();

                {
                    string script    = Ground.ScriptManager.GetJSCode();
                    string component = Ground.ComponentManager.GetJSCode();
                    string css       = Ground.ComponentManager.GetCSSCode();

                    gir.AddJSCode(script);
                    gir.AddJSCode(component);

                    script    = gir.ResolveJSCode(script);
                    component = gir.ResolveJSCode(component);
                    css       = gir.ResolveCSSCode(css);

                    outHtmlFormat = StringTools.MultiReplace(outHtmlFormat,
                                                             "riot_script",
                                                             script,
                                                             "riot_component",
                                                             component,
                                                             "riot_css",
                                                             css,
                                                             "riot_testmain",
                                                             TESTMAIN_PTN
                                                             );
                }

                {
                    string outHtml = outHtmlFormat;

                    outHtml = StringTools.MultiReplace(outHtml,
                                                       TESTMAIN_PTN,
                                                       ""
                                                       );

                    outHtml = CommonUtils.ToHTMLNewLine(outHtml);

                    File.WriteAllText(Ground.OutHtmlFile, outHtml, Encoding.UTF8);
                }

                foreach (ScriptFile scriptFile in Ground.ScriptManager.GetTestMainScriptFiles())
                {
                    string outHtml = outHtmlFormat;

                    {
                        string script = scriptFile.GetJSCode();

                        gir.AddJSCode(script);

                        script = gir.ResolveJSCode(script);

                        outHtml = StringTools.MultiReplace(outHtml,
                                                           TESTMAIN_PTN,
                                                           script
                                                           );
                    }

                    outHtml = CommonUtils.ToHTMLNewLine(outHtml);

                    File.WriteAllText(Ground.OutTestMainHtmlFileBase + scriptFile.CoName + Consts.OUT_TEST_MAIN_HTML_SUFFIX, outHtml, Encoding.UTF8);
                }

                if (noOpenOutput == false)
                {
                    OpenOutput();
                }

                HtmlFileOptimizer.Perform(
                    Ground.OutHtmlFile,
                    Ground.OutHtmlFile_Slimmed,
                    ScriptOptimizer.Slim
                    );

                HtmlFileOptimizer.Perform(
                    Ground.OutHtmlFile_Slimmed,
                    Ground.OutHtmlFile_Slimmed_Wrapped,
                    ScriptOptimizer.Wrap
                    );
            }
        }