コード例 #1
0
        private void OnFileEvent(object sender, FileSystemEventArgs e)
        {
            Thread.Sleep(1);

            string name = e.Name.Substring(0, e.Name.Length - 3);

            name = name.Substring(name.LastIndexOf("/") + 1);
            name = name.Substring(name.LastIndexOf("\\") + 1);

            string root  = watcher_to_root[sender];
            string input = null;

            try
            {
                input = File.ReadAllText(e.FullPath);
            }
            catch (Exception)
            {
                compile_info[root][name] = string.Format("Failed to read file.");
                UpdateGui();
                return;
            }

            TargetCppResult result = null;

            try
            {
                result = SugarCompiler.Compile(input, name);
            }
            catch (Exception err)
            {
                compile_info[root][name] = string.Format("Compile Error:\n{0}", err);
                Console.WriteLine("Compile Error!");
                UpdateGui();
                return;
            }

            try
            {
                File.WriteAllText(root + "/" + name + ".h", result.Header);
                File.WriteAllText(root + "/" + name + ".cpp", result.Implementation);
            }
            catch (Exception)
            {
                compile_info[root][name] = string.Format("Can't access file.");
                UpdateGui();
                return;
            }

            compile_info[root][name] = null;
            Console.WriteLine("Compile Success!");
            UpdateGui();
        }
コード例 #2
0
ファイル: Compile.cs プロジェクト: noobshow/SugarCpp
        internal static void DoCompile(string inputFileName, string arguments)
        {
            string cppFileName = Path.GetTempFileName();

            string          input  = File.ReadAllText(inputFileName);
            TargetCppResult result = null;

            try
            {
                result = SugarCompiler.Compile(input, cppFileName);
            }
            catch (Exception ex)
            {
                Program.Panic(string.Format("Compile Error:\n{0}", ex.Message));
            }
            // Write to temperory file
            File.Delete(cppFileName);
            File.WriteAllText(cppFileName + ".h", result.Header);
            File.WriteAllText(cppFileName + ".cpp", result.Implementation);

            // Execute compiler
            RunCommand(compiler.Command, cppFileName + ".cpp" + " " + arguments + " " + compiler.AdditionalArgs);
        }