Esempio n. 1
0
    public void Compile()
    {
        Debug.Log("Resolving File: " + m_SourceFileText.text);
        string target = m_SourceFileText.text;

        if (m_SourceFileText.text.StartsWith("http://") || m_SourceFileText.text.StartsWith("https://"))
        {
            string srcPath = Path.Combine(Application.temporaryCachePath, Path.GetFileName(m_SourceFileText.text));

            Debug.Log("Downloading File: " + m_SourceFileText.text);
            Debug.Log("Target: " + srcPath);
            using (WebClient wc = new WebClient())
            {
                wc.DownloadFile(m_SourceFileText.text, srcPath);
            }

            target = srcPath;
        }

        m_Provider.ClearUpdateAddrList();

        string file = CompilerHelper.Compile(
            target,
            Path.Combine(AppRootHelper.AppRoot, "build"),
            Path.Combine(AppRootHelper.AppRoot, "temp"),
            true,
            new[] { "HL-expr", "bin" });

        m_LastCompile = File.ReadAllBytes(file);
    }
Esempio n. 2
0
 public static string Compile(string file, bool clean)
 {
     return(CompilerHelper.Compile(
                file,
                FirstSetup.OutputDirectory,
                FirstSetup.InternalDirectory,
                clean,
                new[] { "HL-expr", "bin" }
                ));
 }
Esempio n. 3
0
        private static void Compile()
        {
            // Generate the ztwp file

            var pkg = PackageController.CurrentPackage;

            if (!pkg.DoesSetupExists)
            {
                throw new Exception(TesterException);
            }

            // Step 0: Check if setup file has the needed methods (OnSetup && OnFinish)
            {
                Assembly asm;
                if (!PackageHelper.GetAssembly(pkg, out asm))
                {
                    CurrentProgram.Exit();
                    return;
                }

                if (!asm.HasMethod(pkg.SetupFullname, PackageConsts.OnSetupMethod) || !asm.HasMethod(pkg.SetupFullname, PackageConsts.OnFinishMethod))
                {
                    Console.WriteLine($"There are missing methods on '{pkg.SetupFullname}' in '{pkg.SetupPath}'. Please, add them before trying to compile.", Color.Red);

                    CurrentProgram.Exit();
                    return;
                }
            }

            // Step 1: Create a temp folder where everything will be stored
            string tempFolder = IOHelper.GetTemporaryDirectory(pkg.TempPrefix, "", false),
                   outputDir  = CreateFolderStructure(tempFolder);

            // Step 2: Compile solution to generate a exe file (csc)
            bool isSuccesful = CompilerHelper.Compile(pkg.SolutionPath, outputDir);

            if (!isSuccesful)
            {
                CurrentProgram.Exit();
                return;
            }

            // Note: The structure of the package will be as following:
            // root
            // info.json
            // (pkgName)Setup.cs
            // Package/
            // files (exe, libs, etc etc)

            // Step 3: Search for the Setup of pkg and copy on this folder and generate needed files
            {
                if (!pkg.DoesSetupExists)
                {
                    throw new Exception(TesterException);
                }

                // We will only copy the *.cs (hint: OnSetup) file.
                File.Copy(pkg.SetupPath, Path.Combine(tempFolder, pkg.SetupFileName));

                // Then, we will generate info.json and copy into the folder
                File.WriteAllText(Path.Combine(tempFolder, "info.json"), JsonConvert.SerializeObject(pkg));
            }

            // Step 4: Zip everything into a ".ztwp" extension file
            string compressedFile = CompressionHelper.Zip(tempFolder, Path.GetTempPath(), ZTWPackage.Extension);

            // Step 4.1: Remove Directory
            if (!IOHelper.EmptyFolder(tempFolder))
            {
                throw new Exception("Couldn't empty the temp folder!");
            }

            // Step 5: Open file in Explorer

            //Process.Start($"file://{compressedFile}"); // Search or work in a cross-platform solution for this
            Process.Start(Path.GetTempPath());

            CurrentProgram.Exit();
        }