コード例 #1
0
 public void TestDeleteContents()
 {
     using (var dir = new TemporaryDirectory())
     {
         var subDirPath     = Path.Combine(dir.Path, "subDir");
         var subDirFilePath = Path.Combine(subDirPath, "file");
         var filePath       = Path.Combine(dir.Path, "file");
         Directory.CreateDirectory(subDirPath);
         File.WriteAllText(subDirFilePath, "");
         File.WriteAllText(filePath, "");
         DirectoryEx.DeleteContents(dir.Path);
         Assert.IsFalse(File.Exists(filePath));
         Assert.IsFalse(Directory.Exists(subDirPath));
         Assert.IsTrue(Directory.Exists(dir.Path));
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates a compiler instance based on the <see cref="StubType" /> of <paramref name="project" />.
        /// </summary>
        /// <param name="project">The project to compile.</param>
        /// <param name="intermediateDirectory">The intermediate directory path to store temporary files during compilations.</param>
        /// <param name="outputFileName">The path to the final output file.</param>
        /// <param name="errors">The <see cref="ErrorCollection" /> to write compilation errors to.</param>
        /// <returns>A new instance of a class that inherits <see cref="ProjectCompiler" />.</returns>
        public static ProjectCompiler Create(ProjectFile project, string intermediateDirectory, string outputFileName, ErrorCollection errors)
        {
            DirectoryEx.DeleteContents(intermediateDirectory, true);
            Directory.CreateDirectory(Path.Combine(intermediateDirectory, "src"));
            Directory.CreateDirectory(Path.Combine(intermediateDirectory, "bin"));

            switch (project.Stub.Type)
            {
            case StubType.Pe32:
                return(new Pe32Compiler(project, intermediateDirectory, outputFileName, errors));

            case StubType.DotNet32:
            case StubType.DotNet64:
                return(new DotNetCompiler(project, intermediateDirectory, outputFileName, errors));

            default:
                throw new InvalidEnumArgumentException();
            }
        }
コード例 #3
0
        private async Task <int> RunAsync(string[] remainingArguments)
        {
            var configFilePath = remainingArguments[0];

            PatchInfo patchInfo = null;
            var       errors    = new List <string>();

            try
            {
                var configString = File.ReadAllText(configFilePath);
                patchInfo = JsonConvert.DeserializeObject <PatchInfo>(configString);
                if (patchInfo == null)
                {
                    errors.Add("No configuration was read.");
                }
            }
            catch (Exception e)
            {
                errors.Add("Failed to read configuration file. " + e.Message);
            }

            if (patchInfo != null)
            {
                if (patchInfo.OldPath == "" || !Directory.Exists(patchInfo.OldPath))
                {
                    errors.Add("OldPath was unspecified or does not exist.");
                }

                if (patchInfo.NewPath == "" || !Directory.Exists(patchInfo.NewPath))
                {
                    errors.Add("NewPath was unspecified or path does not exist.");
                }

                if (patchInfo.PatchPath == "")
                {
                    errors.Add("PatchPath path was unspecified.");
                }
            }

            if (errors.Count > 0)
            {
                var example = new PatchInfo
                {
                    OldPath   = Path.Combine("path", "to", "old", "files"),
                    NewPath   = Path.Combine("path", "to", "new", "files"),
                    PatchPath = Path.Combine("path", "to", "place", "output", "files"),
                };
                Console.Error.WriteLine("Invalid configuration. Please specify a configuration file that looks like the following:");
                Console.Error.WriteLine(JsonConvert.SerializeObject(example, Formatting.Indented));
                foreach (var error in errors)
                {
                    Console.Error.WriteLine("Error: " + error);
                }
                return(1);
            }

            if (_removeOutput)
            {
                DirectoryEx.DeleteContents(patchInfo.PatchPath);
            }
            else if (Directory.Exists(patchInfo.PatchPath))
            {
                Console.Error.WriteLine("Warning: Output path already exists. Use --removeoutput to erase its contents.");
            }

            await new RxPatchBuilder().CreatePatchAsync(patchInfo);
            return(0);
        }