Exemplo n.º 1
0
        private static void CopyDirectory(string sourceDirectory, string destinationDirectory, bool overwrite = false)
        {
            sourceDirectory      = DllExportWeaver.GetCleanedDirectoryPath(sourceDirectory);
            destinationDirectory = DllExportWeaver.GetCleanedDirectoryPath(destinationDirectory);
            if (Directory.Exists(destinationDirectory) && !overwrite)
            {
                throw new IOException(Resources.The_destination_directory_already_exists_);
            }
            if (!Directory.Exists(destinationDirectory))
            {
                Directory.CreateDirectory(destinationDirectory);
            }
            int startIndex = sourceDirectory.Length + 1;

            foreach (string directory in Directory.GetDirectories(sourceDirectory, "*", SearchOption.AllDirectories))
            {
                string path = Path.Combine(destinationDirectory, directory.Substring(startIndex));
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            foreach (string file in Directory.GetFiles(sourceDirectory, "*.*", SearchOption.AllDirectories))
            {
                string destFileName = Path.Combine(destinationDirectory, file.Substring(startIndex));
                File.Copy(file, destFileName, overwrite);
            }
        }
 public void Run()
 {
     if (this.Exports == null)
     {
         IExportAssemblyInspector assemblyInspector = Utilities.CreateAssemblyInspector(this.InputValues);
         using (this.GetNotifier().CreateContextName((object)this, Resources.ExtractExportsContextName))
             this.Exports = assemblyInspector.ExtractExports();
         using (this.GetNotifier().CreateContextName((object)this, Resources.FindDuplicateExportMethodsContextName))
         {
             foreach (DuplicateExports duplicateExportMethod in this.Exports.DuplicateExportMethods)
             {
                 if (duplicateExportMethod.Duplicates.Count > 0)
                 {
                     StringBuilder stringBuilder = new StringBuilder(200).AppendFormat("{0}.{1}", (object)duplicateExportMethod.UsedExport.ExportedClass.NullSafeCall <ExportedClass, string>((Func <ExportedClass, string>)(ec => ec.FullTypeName)), (object)duplicateExportMethod.UsedExport.Name);
                     foreach (ExportedMethod duplicate in (IEnumerable <ExportedMethod>)duplicateExportMethod.Duplicates)
                     {
                         stringBuilder.AppendFormat(", {0}.{1}", (object)duplicate.ExportedClass.NullSafeCall <ExportedClass, string>((Func <ExportedClass, string>)(ec => ec.FullTypeName)), (object)duplicate.Name);
                     }
                 }
             }
         }
     }
     if (this.Exports.Count == 0)
     {
         return;
     }
     using (this.GetNotifier().CreateContextName((object)this, Resources.CreateTempDirectoryContextName))
     {
         using (ValueDisposable <string> tempDirectory = Utilities.CreateTempDirectory())
         {
             this.RunIlDasm(tempDirectory.Value);
             bool flag = ((IEnumerable <string>) new string[2]
             {
                 "true",
                 "yes"
             }).Any <string>((Func <string, bool>)(t => t.Equals(this.InputValues.LeaveIntermediateFiles, StringComparison.InvariantCultureIgnoreCase)));
             if (flag)
             {
                 using (this.GetNotifier().CreateContextName((object)this, Resources.CopyBeforeContextName))
                     DllExportWeaver.CopyDirectory(tempDirectory.Value, Path.Combine(Path.GetDirectoryName(this.InputValues.OutputFileName), "Before"), true);
             }
             using (IlAsm ilAsm = this.PrepareIlAsm(tempDirectory.Value))
                 this.RunIlAsm(ilAsm);
             if (!flag)
             {
                 return;
             }
             using (this.GetNotifier().CreateContextName((object)this, Resources.CopyAfterContextName))
                 DllExportWeaver.CopyDirectory(tempDirectory.Value, Path.Combine(Path.GetDirectoryName(this.InputValues.OutputFileName), "After"), true);
         }
     }
 }