コード例 #1
0
        Assembly LoadAssembly(string path, string name)
        {
            var file = Path.Combine(path, name);

            if (loaded.Contains(file))
            {
                return(null);
            }
            loaded.Add(file);
            string path2 = file.Replace("dll", "xml");

            if (File.Exists(path2))
            {
                HelpXml.AddRange(XmlMember.LoadHelpXml(path2));
            }
            var p2  = Path.GetDirectoryName(GetType().Assembly.Location);
            var asm = Assembly.LoadFile(file);

            IOHelper.CopyPath(path, p2, "*.dll", false, false);
            System.Diagnostics.Trace.WriteLine(Path.Combine(path, name));
            foreach (var friend in asm.GetReferencedAssemblies())
            {
                file = Path.Combine(path, friend.Name + ".dll");
                if (File.Exists(file))
                {
                    LoadAssembly(path, friend.Name + ".dll");
                }
            }
            return(asm);
        }
コード例 #2
0
                                          BindingFlags.Public | BindingFlags.NonPublic; //指定非公共成员将包括在搜索中。

        #endregion

        #region 流程

        /// <summary>
        /// 准备
        /// </summary>
        /// <returns></returns>
        public bool Prepare()
        {
            var dir  = Path.GetDirectoryName(FileName);
            var root = Path.GetDirectoryName(GetType().Assembly.Location);

            IOHelper.CopyPath(dir, root);
            var file = Path.Combine(root, Path.GetFileName(FileName));

            try
            {
                _assembly = Assembly.LoadFile(file);
            }
            catch (Exception e)
            {
                return(false);
            }
            if (_assembly == null)
            {
                return(false);
            }
            Config = new AssemblyConfig
            {
                Name     = _assembly.FullName,
                SaveName = FileName
            };
            string path = FileName.Replace("dll", "xml");

            _helpXml = !File.Exists(path) ? new List <XmlMember>() : XmlMember.Load(path);
            return(true);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: supadmins/AgebullDesigner
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("参数不正确");
                return(1);
            }
            var arg      = args[0].Split('|');
            var fileName = arg[0];

            if (!File.Exists(fileName))
            {
                Console.WriteLine($"文件{fileName}不存在或无法访问!");
                return(2);
            }
            var rootPath = arg[1];

            if (arg[2] == "1")
            {
                var asm = new AssemblyUpgrader
                {
                    FileName = fileName
                };
                if (!asm.Prepare())
                {
                    return(2);
                }
                asm.Analyze();
                asm.End();
                string json = JsonConvert.SerializeObject(asm.Config, Formatting.Indented);
                File.WriteAllText(Path.Combine(rootPath, Path.GetFileNameWithoutExtension(fileName) + ".json"), json);
                return(0);
            }
            var pf   = typeof(Program).Assembly.Location;
            var dir1 = Path.GetDirectoryName(pf);
            var dir2 = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "Agebull_AssemblyAnalyzer");

            IOHelper.CopyPath(dir1, dir2);
            var prog    = Path.Combine(dir2, Path.GetFileName(pf));
            var process = Process.Start(prog, $"{fileName}|{rootPath}|1");

            process.WaitForExit();
            Console.ReadKey();
            return(process.ExitCode);
        }