Exemple #1
0
        private void Compile(string file, bool isTemp)
        {
            var directory  = Directory.GetCurrentDirectory();
            var acc_bin    = Dirs.Bin.ACC.FullName;
            var argBuilder = new List <string>();
            var outputDir  = "bin";

            if (isTemp)
            {
                outputDir = "obj";
            }
            var Project  = AncientProject.FromLocal();
            var fileName = Path.GetFileNameWithoutExtension(file);

            argBuilder.Add($"-o ./{outputDir}/{fileName}");
            if (Project.Extension != null)
            {
                argBuilder.Add($"-e {Project.Extension}");
            }
            argBuilder.Add($"-s \"{file}\"");

            var external = new ExternalTools(acc_bin, string.Join(" ", argBuilder));

            Directory.CreateDirectory(Path.Combine(directory, outputDir));
            external.Start().Wait().ExitCode();
        }
Exemple #2
0
 public Processor(ProcessorArgs processorArgs)
 {
     ProcessorArgs = processorArgs;
     //
     ExternalTools   = new ExternalTools(ProcessorArgs.ConfigurationMain.Paths);
     FileExecution   = new FileExecution(ExternalTools);
     FilePreparation = new FilePreparation(ExternalTools);
     FileInformation = new FileInformation();
 }
Exemple #3
0
        public int Execute(bool isTemp)
        {
            var directory = Directory.GetCurrentDirectory();

            if (!Validate(directory))
            {
                return(1);
            }

            var ancient_home = Environment.GetEnvironmentVariable("ANCIENT_HOME", EnvironmentVariableTarget.User);

            if (ancient_home is null)
            {
                throw new InvalidOperationException($"env variable 'ANCIENT_HOME' is not set.");
            }
            if (!new DirectoryInfo(ancient_home).Exists)
            {
                throw new InvalidOperationException($"Env variable 'ANCIENT_HOME' is invalid.");
            }

            var acc_home = Path.Combine(ancient_home, "compiler");
            var acc_bin  = Path.Combine(acc_home, "acc.exe");

            if (!new DirectoryInfo(acc_home).Exists || !new FileInfo(acc_bin).Exists)
            {
                throw new InvalidOperationException($"Ancient compiler is not installed.");
            }

            var argBuilder = new List <string>();

            var files = Directory.GetFiles(directory, "*.asm");

            var outputDir = "bin";

            if (isTemp)
            {
                outputDir = "obj";
            }
            var Project = AncientProject.FromLocal();

            argBuilder.Add($"-o ./{outputDir}/{Project.Name}");
            if (Project.Extension != null)
            {
                argBuilder.Add($"-e {Project.Extension}");
            }
            argBuilder.Add($"-s \"{files.First()}\"");

            var external = new ExternalTools(acc_bin, string.Join(" ", argBuilder));

            Directory.CreateDirectory(Path.Combine(directory, outputDir));
            return(external.Start().Wait().ExitCode());
        }
Exemple #4
0
        internal int Execute(CommandOption isDebug, CommandOption keepMemory, CommandOption fastWrite)
        {
            var dir = Directory.GetCurrentDirectory();

            if (!Validate(dir))
            {
                return(1);
            }

            var ancient_home = Environment.GetEnvironmentVariable("ANCIENT_HOME", EnvironmentVariableTarget.User);

            if (ancient_home is null)
            {
                throw new InvalidOperationException($"env variable 'ANCIENT_HOME' is not set.");
            }
            if (!new DirectoryInfo(ancient_home).Exists)
            {
                throw new InvalidOperationException($"Env variable 'ANCIENT_HOME' is invalid.");
            }

            var vm_home = Path.Combine(ancient_home, "vm");
            var vm_bin  = Path.Combine(vm_home, "vm.exe");

            if (!new DirectoryInfo(vm_home).Exists || !new FileInfo(vm_bin).Exists)
            {
                throw new InvalidOperationException($"Ancient VM is not installed.");
            }

            var argBuilder = new List <string>();

            var files = Directory.GetFiles(Path.Combine("obj"), "*.*")
                        .Where(x => x.EndsWith(".dlx") || x.EndsWith(".bios"));

            argBuilder.Add($"\"{Path.Combine("obj", Path.GetFileNameWithoutExtension(files.First()))}\"");


            var external = new ExternalTools(vm_bin, string.Join(" ", argBuilder));

            return(external
                   .WithEnv("VM_ATTACH_DEBUGGER", isDebug.BoolValue.HasValue)
                   .WithEnv("VM_KEEP_MEMORY", keepMemory.BoolValue.HasValue)
                   .WithEnv("VM_MEM_FAST_WRITE", fastWrite.BoolValue.HasValue)
                   .WithEnv("CLI", true)
                   .WithEnv("CLI_WORK_PATH", dir)

                   .Start()
                   .Wait().ExitCode());
        }
Exemple #5
0
        private static IEnumerable <string> GetProbingPaths(ExternalTools tool)
        {
            var currentAssemblyFolder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            if (currentAssemblyFolder != null)
            {
                yield return(Path.Combine(currentAssemblyFolder, $"Tools-{tool}"));
            }

            var path = Environment.GetEnvironmentVariable("PATH");

            if (path != null)
            {
                foreach (var pathElement in path.Split(';').Where(p => !string.IsNullOrWhiteSpace(p)).Select(p => p.Trim()))
                {
                    yield return(pathElement);
                }
            }

            // heuristics
            switch (tool)
            {
            case ExternalTools.Git:
                yield return(Environment.ExpandEnvironmentVariables(@"%ProgramW6432%\Git\bin"));

                break;

            case ExternalTools.MsBuild:
                var editions        = new[] { "Community", "Professional", "Enterprise" };
                var versions        = new[] { "2017", "2019" };
                var msBuildVersions = new[] { "Current", "15.0" };
                foreach (var version in versions)
                {
                    foreach (var edition in editions)
                    {
                        foreach (var msBuildVersion in msBuildVersions)
                        {
                            yield return(Environment.ExpandEnvironmentVariables($@"%ProgramFiles(x86)%\Microsoft Visual Studio\{version}\{edition}\MSBuild\{msBuildVersion}\Bin"));
                        }
                    }
                }
                break;
            }
        }
Exemple #6
0
        public static string GetToolPath(ExternalTools tool, Action <string> consoleWriteLine)
        {
            if (_locationCache.TryGetValue(tool, out var toolPath))
            {
                return(toolPath);
            }

            var executable = $"{tool}.exe";

            toolPath = GetToolPathInternal(tool, executable);
            if (toolPath == null)
            {
                throw new InvalidOperationException($"Could not find tool: {executable}. Try adding it to PATH or declaring an environment variable: {GetConfigEnvVarName(tool)}");
            }

            consoleWriteLine($"Found {tool} at '{toolPath}'");
            _locationCache = _locationCache.Add(tool, toolPath);
            return(toolPath);
        }
Exemple #7
0
        private static string GetToolPathInternal(ExternalTools tool, string executable)
        {
            var configuredPath = Environment.GetEnvironmentVariable(GetConfigEnvVarName(tool));

            if (configuredPath != null)
            {
                return(configuredPath);
            }

            var probingPaths = GetProbingPaths(tool);

            foreach (var probingPath in probingPaths)
            {
                var executablePath = Path.Combine(probingPath, executable);
                if (File.Exists(executablePath))
                {
                    return(executablePath);
                }
            }

            return(null);
        }
		void RunExternalTool (ExternalTools.ExternalTool tool, string argumentsTool)
		{
			string commandTool = StringParserService.Parse (tool.Command);
			string initialDirectoryTool = StringParserService.Parse (tool.InitialDirectory);

			//Execute tool
			IProgressMonitor progressMonitor = IdeApp.Workbench.ProgressMonitors.GetRunProgressMonitor ();
			try {
				progressMonitor.Log.WriteLine (GettextCatalog.GetString ("Running: {0} {1}", (commandTool), (argumentsTool)));
				progressMonitor.Log.WriteLine ();

				ProcessWrapper processWrapper;
				if (tool.UseOutputPad)
					processWrapper = Runtime.ProcessService.StartProcess (commandTool, argumentsTool, initialDirectoryTool, progressMonitor.Log, progressMonitor.Log, null);
				else
					processWrapper = Runtime.ProcessService.StartProcess (commandTool, argumentsTool, initialDirectoryTool, null);

				string processName = System.IO.Path.GetFileName (commandTool);
				try {
					processName = processWrapper.ProcessName;
				} catch (SystemException) {
				}

				processWrapper.WaitForOutput ();

				if (processWrapper.ExitCode == 0) {
					progressMonitor.Log.WriteLine (GettextCatalog.GetString ("Process '{0}' has completed succesfully", processName));
				} else {
					progressMonitor.Log.WriteLine (GettextCatalog.GetString ("Process '{0}' has exited with error code {1}", processName, processWrapper.ExitCode));
				}
			} catch (Exception ex) {
				progressMonitor.ReportError (GettextCatalog.GetString ("External program execution failed.\nError while starting:\n '{0} {1}'", commandTool, argumentsTool), ex);
			} finally {
				progressMonitor.Dispose ();
			}

		}
Exemple #9
0
        internal async Task <int> Execute(CommandOption isDebug, CommandOption keepMemory, CommandOption fastWrite, CommandOption isInteractive)
        {
            var dir = Directory.GetCurrentDirectory();

            if (!this.Validate(dir))
            {
                return(await Fail());
            }

            if (!Dirs.Bin.VM.Exists)
            {
                return(await Fail($"VM is not installed. Try 'rune install vm'"));
            }


            var vm_bin = Dirs.Bin.VM.FullName;


            var argBuilder = new List <string>();

            if (!Directory.Exists("obj"))
            {
                Directory.CreateDirectory("obj");
            }

            var files = Directory.GetFiles(Path.Combine("obj"), "*.*")
                        .Where(x => x.EndsWith(".dlx") || x.EndsWith(".bios")).ToArray();

            if (files.Length > 1 && !files.Any(x => x.Contains("entry")))
            {
                return(await Fail($"Cannot find 'entry.dlx'"));
            }

            string GetRunArg(Func <string, bool> predicate)
            {
                var target    = files.First(predicate);
                var formatted = Path.GetFileNameWithoutExtension(target);

                return($"\"{Path.Combine("obj", formatted)}\"");
            }

            argBuilder.Add(files.Length == 1 ?
                           GetRunArg(_ => true) :
                           GetRunArg(x => x.Contains("entry")));

            var external = new ExternalTools(vm_bin, string.Join(" ", argBuilder));

            var result = external
                         .WithEnv("VM_ATTACH_DEBUGGER", isDebug.BoolValue.HasValue)
                         .WithEnv("VM_KEEP_MEMORY", keepMemory.BoolValue.HasValue)
                         .WithEnv("VM_MEM_FAST_WRITE", fastWrite.BoolValue.HasValue)
                         .WithEnv("REPL", isInteractive.BoolValue.HasValue)
                         .WithEnv("CLI", true)
                         .WithEnv("CLI_WORK_PATH", dir);

            try
            {
                return(result
                       .Start()
                       .Wait()
                       .ExitCode());
            }
            catch (Win32Exception e) // AccessDenied on linux
            {
                WriteLine($"{":x:".Emoji()} {e.Message}");
                return(await Fail($"Run [chmod +x \"{vm_bin}\"] for resolve this problem."));
            }
        }
Exemple #10
0
 private static bool SolutionMatch(ExternalTools externalTools)
 {
     return(Regex.IsMatch(Path.GetFileNameWithoutExtension(DteExtensions.DTE.Solution.FileName) + "",
                          externalTools.SolutionRegex));
 }
Exemple #11
0
        IEnumerator CreateInitialData()
        {
            HttpWrapper wrapper = new HttpWrapper();

            //Get ChannelInfo
            ChannelInfo channelInfo = null;

            wrapper.RequestInfo <ChannelInfo>(GetAbsoluteURL(m_PlaylistName), info => { channelInfo = info; });
            yield return(new WaitUntil(wrapper.RequestFinished));

            if (channelInfo != null)
            {
                //Get PlayLists and others
                m_StreamPlayListName = channelInfo.stream_info;
                m_AudioPlayListName  = channelInfo.audio_info;
                m_PollingInterval    = channelInfo.frame_interval * channelInfo.combined_frames;

                //Get CombinedData
                byte[] combinedData = null;
                wrapper.RequestBinary(GetAbsoluteURL(channelInfo.data), bin => {
                    if (bin != null)
                    {
                        combinedData = ExternalTools.Decompress(bin);
                    }
                });
                yield return(new WaitUntil(wrapper.RequestFinished));

                if (combinedData == null)
                {
                    yield break;
                }

                StreamingMeshRenderer meshRenderer = new StreamingMeshRenderer
                {
                    ContainerSize  = channelInfo.container_size,
                    PackageSize    = channelInfo.package_size,
                    FrameInterval  = channelInfo.frame_interval,
                    CombinedFrames = channelInfo.combined_frames
                };

                StreamingAudioRenderer audioRenderer = new StreamingAudioRenderer
                {
                    FrameInterval  = channelInfo.frame_interval,
                    CombinedFrames = channelInfo.combined_frames
                };
#if !UNITY_WEBGL
                if (!string.IsNullOrEmpty(channelInfo.audio_info))
                {
                    m_AudioRenderer = audioRenderer;
                }
#else
                if (!string.IsNullOrEmpty(channelInfo.audio_clip))
                {
                    m_AudioRenderer = audioRenderer;
                }
#endif

                //Split Textures and Materials and Mesh from CombinedData
                int offsetBytes = 0;

                //Split Textures
                List <string> textureNames = channelInfo.textures;
                List <int>    textureSizes = channelInfo.textureSizes;
                for (int i = 0; i < textureSizes.Count; i++)
                {
                    int       size    = textureSizes[i];
                    Texture2D texture = TextureConverter.DeserializeFromBinary(combinedData, offsetBytes, size);
                    string    name    = textureNames[i];
                    if (texture != null)
                    {
                        meshRenderer.AddTexture(name, texture);
                    }
                    offsetBytes += size;
                    yield return(null);
                }

                //Split Materials
                List <string> materialNames = channelInfo.materials;
                List <int>    materialSizes = channelInfo.materialSizes;
                for (int i = 0; i < materialSizes.Count; i++)
                {
                    int      size     = materialSizes[i];
                    Material material = MaterialConverter.DeserializeFromBinary(
                        combinedData, offsetBytes, size, m_CustomShaders, m_DefaultShader, meshRenderer.TextureDictionary);
                    string name = material.name;
                    meshRenderer.AddMaterial(name, material);
                    offsetBytes += size;
                    yield return(null);
                }

                GameObject rootGameObject = new GameObject("RootGameObject");
                rootGameObject.transform.SetParent(transform, false);

                //Split Meshes
                List <string> meshNames = channelInfo.meshes;
                List <int>    meshSizes = channelInfo.meshSizes;
                for (int i = 0; i < meshSizes.Count; i++)
                {
                    string        name         = meshNames[i];
                    int           size         = meshSizes[i];
                    List <string> refMaterials = null;
                    Mesh          mesh         = MeshConverter.DeserializeFromBinary(
                        combinedData, offsetBytes, size, channelInfo.container_size, out refMaterials);

                    List <Material> materials = new List <Material>();
                    for (int j = 0; j < refMaterials.Count; j++)
                    {
                        Material material = null;
                        if (meshRenderer.MaterialDictionary.TryGetValue(refMaterials[i], out material))
                        {
                            materials.Add(material);
                            yield return(null);
                        }
                    }

                    GameObject obj = new GameObject("Mesh_" + name);
                    obj.transform.SetParent(rootGameObject.transform, false);
                    MeshFilter   meshFilter = obj.AddComponent <MeshFilter>();
                    MeshRenderer renderer   = obj.AddComponent <MeshRenderer>();

                    meshFilter.mesh    = mesh;
                    renderer.materials = materials.ToArray();
                    meshRenderer.AddMesh(name, mesh);
                    offsetBytes += size;
                    yield return(null);
                }

                //CreateVertexBuffer;
                meshRenderer.CreateVertexBuffer();
                meshRenderer.CreateVertexContainer(channelInfo.package_size, channelInfo.container_size);
                meshRenderer.RootGameObject = rootGameObject;
                m_MeshRenderer = meshRenderer;
            }
        }
Exemple #12
0
        private void StartProcess3(object o)
        {
            try
            {
                ProcessorArgs     processorArgs = (ProcessorArgs)o;
                ConfigurationMain mainCfg       = processorArgs.ConfigurationMain;
                //
                FileExecution.ExecuteTreat(processorArgs.Orders, mainCfg, false);
                //
                if (mainCfg.PassBsa.Enabled)
                {
                    if (mainCfg.PassBsa.MustRepack())
                    {
                        FileExecution.RepackBsa(processorArgs.BsaOrders, mainCfg.PassBsa.GameParameter, mainCfg.IsUseMultithreading, mainCfg.IsVerbose);
                    }
                    if (mainCfg.PassBsa.MustClean())
                    {
                        FileExecution.CleanBsa(processorArgs.BsaOrders, mainCfg.IsVerbose);
                    }
                }
                //
                if (mainCfg.IsMergeActivated)
                {
                    if (mainCfg.IsUnmergeActivated)
                    {
                        FileExecution.DeleteFiles(mainCfg, processorArgs.DeleteOrders);
                    }
                    else
                    {
                        FileExecution.Merge(mainCfg, processorArgs.CopyOrders);
                    }
                }
                //
                if (mainCfg.PassBsa.Enabled && mainCfg.PassBsa.IsRepackLooseFilesInBsa)
                {
                    var bsaToProcess = mainCfg.PassBsa.IsIntelligentPacking ?
                                       FileUtils.GetIntelligentPacking(mainCfg.Selection, mainCfg.PathSource, mainCfg.PassBsa.GameParameter, mainCfg.PassBsa.IsRepackCreateDummy, mainCfg.IsVerbose) :
                                       FileUtils.PrepareForPacking(mainCfg.PassBsa.Repacks, mainCfg.PathSource, mainCfg.PassBsa.GameParameter, true, mainCfg.IsVerbose);



                    List <DirectoryInfo> dirToDeleteIfFail = new List <DirectoryInfo>();
                    foreach (InformationRepackBsa informationRepackBsa in bsaToProcess)
                    {
                        ExternalTools.CallBsaPack(Path.Combine(informationRepackBsa.Source.FullName, informationRepackBsa.CurrentBsaName),
                                                  informationRepackBsa.CurrentTarget.FullName, informationRepackBsa.IsCompressed, informationRepackBsa.GameParameter, mainCfg.IsUseMultithreading, mainCfg.IsVerbose);
                        //
                        informationRepackBsa.CurrentTarget.Refresh();
                        if (informationRepackBsa.CurrentTarget.Exists)
                        {
                            try
                            {
                                FileUtils.DeleteCompleteDirectory(informationRepackBsa.CurrentTarget);
                            }
                            catch
                            {
                                dirToDeleteIfFail.Add(informationRepackBsa.CurrentTarget);
                            }
                        }
                    }
                    //
                    foreach (DirectoryInfo directoryInfo in dirToDeleteIfFail)
                    {
                        FileUtils.DeleteCompleteDirectory(directoryInfo);
                    }
                }
                //Cleaning empty subdir
                if (mainCfg.IsBackupActivated && mainCfg.IsRefreshBackup)
                {
                    FileInformation.CleanEmptySubdir(mainCfg.PathBackup);
                }
                //Cleaning no present source subdir
                if (mainCfg.IsBackupActivated && mainCfg.IsCleanBackup)
                {
                    FileInformation.CleanBackupFromSource(mainCfg.PathSource, mainCfg.PathBackup);
                }
                //
                if (mainCfg.IsShowResults)
                {
                    var infoTextures = new DirectoryInfo(mainCfg.PathSource);
                    //
                    foreach (var directoryInfo in infoTextures.GetDirectories())
                    {
                        processorArgs.Folders[directoryInfo.Name].NewSize = FileUtils.CalculateDirectorySizeMo(directoryInfo, mainCfg.PassBsa.Enabled);
                    }
                    processorArgs.Folders[infoTextures.Name].NewSize = FileUtils.CalculateDirectorySizeMo(infoTextures, mainCfg.PassBsa.Enabled);
                    // Show sizes before/after resizes
                    Logger.Log("Results: (Size before resize in Mo => current size in Mo)");
                    foreach (var keyValuePair in processorArgs.Folders.OrderBy(e => e.Value.Size))
                    {
                        Logger.Log("{0,15:F2} Mo => {1,15:F2} Mo {2}",
                                   keyValuePair.Value.Size,
                                   keyValuePair.Value.NewSize,
                                   keyValuePair.Key);
                    }
                }

                OnProcessorEnded(-1);
            }
            catch (AggregateException e)
            {
                Logger.Log(e);
                foreach (Exception innerException in e.InnerExceptions)
                {
                    Logger.Log(innerException);
                }
                OnProcessorEnded(-1);
            }
            catch (Exception e)
            {
                Logger.Log(e);
                OnProcessorEnded(-1);
            }
        }
Exemple #13
0
 private static string GetConfigEnvVarName(ExternalTools tool)
 => $"DEVEROOM_TEST_TOOLPATH_{tool}";
		public RunCustomToolHandler (ExternalTools.ExternalTool tool)
		{
			this.tool = tool;
		}