private int RunLibTool(CpuPlatform cpu, string fileName, string directory)
        {
            if (string.IsNullOrEmpty(this.InputValues.LibToolPath))
            {
                return(0);
            }
            string libraryFileNameRoot = IlAsm.GetLibraryFileNameRoot(fileName);
            string defFile             = this.CreateDefFile(cpu, directory, libraryFileNameRoot);

            try
            {
                return(this.RunLibToolCore(cpu, directory, defFile));
            }
            catch (Exception ex)
            {
                this.Notifier.Notify(1, DllExportLogginCodes.LibToolLooging, Resources.An_error_occurred_while_calling_0_1_, (object)"lib.exe", (object)ex.Message);
                return(-1);
            }
            finally
            {
                if (File.Exists(defFile))
                {
                    File.Delete(defFile);
                }
            }
        }
Beispiel #2
0
        private int RunLibTool(CpuPlatform cpu, string fileName, string directory)
        {
            if (!InputValues.GenExpLib)
            {
                return(0);
            }

            string libFileRoot = IlAsm.GetLibraryFileNameRoot(fileName);
            string defFile     = CreateDefFile(cpu, directory, libFileRoot);
            string path        = Path.Combine(directory, Path.GetFileNameWithoutExtension(InputValues.OutputFileName)) + ".lib";
            string cfg         = $"\"/def:{defFile}\" /machine:{cpu} \"/out:{path}\"";

            try
            {
                Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"VsDevCmd: {InputValues.VsDevCmd}");
                if (!String.IsNullOrWhiteSpace(InputValues.VsDevCmd))
                {
                    int code = RunLibToolCore(
                        "cmd",
                        $"/C \"\"{InputValues.VsDevCmd}\" -no_logo -arch={(cpu == CpuPlatform.X64 ? "amd64" : "x86")} && lib.exe {cfg}\""
                        );

                    Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"lib tool via VsDevCmd: {code}");
                    if (code == 0)
                    {
                        return(code);
                    }
                }

                Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"LibToolPath: {InputValues.LibToolPath}");
                if (!String.IsNullOrWhiteSpace(InputValues.LibToolPath))
                {
                    string reqPath = (String.IsNullOrEmpty(InputValues.LibToolDllPath) || !Directory.Exists(InputValues.LibToolDllPath)) ? null : InputValues.LibToolDllPath;
                    int    code    = RunLibToolCore("Lib.exe", cfg, InputValues.LibToolPath, reqPath);

                    Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"lib tool via LibToolPath: {code}");
                    if (code == 0)
                    {
                        return(code);
                    }
                }

                Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"VcVarsAll: {InputValues.VcVarsAll}");
                if (!String.IsNullOrWhiteSpace(InputValues.VcVarsAll))
                {
                    int code = RunLibToolCore(
                        "cmd",
                        $"/C \"\"{InputValues.VcVarsAll}\" {(cpu == CpuPlatform.X64 ? "x64" : "x86")} && lib.exe {cfg}\""
                        );

                    Notifier.Notify(-1, DllExportLogginCodes.LibToolLooging, $"lib tool via VcVarsAll: {code}");
                    if (code == 0)
                    {
                        return(code);
                    }
                }

                int ret = RunLibToolCore("lib.exe", cfg, String.Empty, InputValues.LibToolDllPath);
                Notifier.Notify(0, DllExportLogginCodes.LibToolLooging, $"lib tool via LibToolDllPath '{InputValues.LibToolDllPath}': {ret}");
                if (ret != -1)
                {
                    return(ret);
                }

                throw new FileNotFoundException("The library manager still cannot be found or something went wrong.");
            }
            catch (Exception ex)
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                Notifier.Notify(1, DllExportLogginCodes.LibToolLooging, Resources.An_error_occurred_while_calling_0_1_, "lib.exe", ex.Message);
                return(-1);
            }
            finally
            {
                if (File.Exists(defFile))
                {
                    File.Delete(defFile);
                }
            }
        }