Exemple #1
0
        protected int TrackerExecuteTool(
            string toolPath, string responseFileCommands, string commandLineCommands)
        {
            bool   trackFileAccess = TrackFileAccess;
            string command         = Environment.ExpandEnvironmentVariables(toolPath);
            string rspFileCommands = responseFileCommands;
            string arguments       = Environment.ExpandEnvironmentVariables(commandLineCommands);

            string rspFile = null;

            try {
                string trackerPath;
                string dllName = null;
                pathToLog = command;
                if (trackFileAccess)
                {
                    var toolType = ExecutableType.SameAsCurrentProcess;
                    if (!string.IsNullOrEmpty(ToolArchitecture))
                    {
                        if (!Enum.TryParse(ToolArchitecture, out toolType))
                        {
                            Log.LogErrorWithCodeFromResources(
                                nameof(Strings.General_InvalidValue),
                                "ToolArchitecture",
                                GetType().Name);
                            return(-1);
                        }
                    }
                    else if (ToolType.HasValue)
                    {
                        toolType = ToolType.Value;
                    }

                    try {
                        trackerPath = FileTracker.GetTrackerPath(toolType, TrackerSdkPath);
                        if (trackerPath == null)
                        {
                            Log.LogErrorFromResources(
                                nameof(Strings.Error_MissingFile),
                                "tracker.exe");
                        }
                    } catch (Exception ex) when(!ExceptionHandling.NotExpectedException(ex))
                    {
                        Log.LogErrorWithCodeFromResources(
                            nameof(Strings.General_InvalidValue),
                            "TrackerSdkPath",
                            GetType().Name);
                        return(-1);
                    }

                    try {
                        dllName = FileTracker.GetFileTrackerPath(
                            toolType, TrackerFrameworkPath);
                    } catch (Exception ex) when(!ExceptionHandling.NotExpectedException(ex))
                    {
                        Log.LogErrorWithCodeFromResources(
                            nameof(Strings.General_InvalidValue),
                            "TrackerFrameworkPath",
                            GetType().Name);
                        return(-1);
                    }
                }
                else
                {
                    trackerPath = command;
                }

                if (string.IsNullOrEmpty(trackerPath))
                {
                    return(-1);
                }

                ErrorUtilities.VerifyThrowInternalRooted(trackerPath);
                string cmdLineCommands;
                if (trackFileAccess)
                {
                    string trackerArgs = FileTracker.TrackerArguments(
                        command, arguments, dllName,
                        TrackerIntermediateDirectory, RootSource,
                        CancelEventName);

                    Log.LogMessageFromResources(
                        MessageImportance.Low,
                        nameof(Strings.Native_TrackingCommandMessage));
                    Log.LogMessage(
                        MessageImportance.Low,
                        trackerPath + (AttributeFileTracking ? " /a " : " ") +
                        trackerArgs + " " + rspFileCommands);

                    rspFile = FileUtilities.GetTemporaryFile();
                    using (var writer = CreateUnicodeWriter(rspFile)) {
                        writer.Write(FileTracker.TrackerResponseFileArguments(
                                         dllName, TrackerIntermediateDirectory, RootSource, CancelEventName));
                    }

                    cmdLineCommands =
                        (AttributeFileTracking ? "/a @\"" : "@\"") + rspFile +
                        "\"" + FileTracker.TrackerCommandArguments(command, arguments);
                }
                else
                {
                    cmdLineCommands = arguments;
                }

                return(base.ExecuteTool(trackerPath, rspFileCommands, cmdLineCommands));
            } finally {
                if (rspFile != null)
                {
                    DeleteTempFile(rspFile);
                }
            }
        }
        protected int TrackerExecuteTool(string pathToTool, string responseFileCommands, string commandLineCommands)
        {
            string dllName               = (string)null;
            string str1                  = (string)null;
            bool   trackFileAccess       = this.TrackFileAccess;
            string str2                  = Environment.ExpandEnvironmentVariables(pathToTool);
            string responseFileCommands1 = responseFileCommands;
            string arguments             = Environment.ExpandEnvironmentVariables(commandLineCommands);

            try
            {
                this.pathToLog = str2;
                string pathToTool1;
                if (trackFileAccess)
                {
                    ExecutableType result = ExecutableType.SameAsCurrentProcess;
                    if (!string.IsNullOrEmpty(this.ToolArchitecture))
                    {
                        if (!Enum.TryParse <ExecutableType>(this.ToolArchitecture, out result))
                        {
                            this.Log.LogErrorWithCodeFromResources("General.InvalidValue", (object)"ToolArchitecture", (object)this.GetType().Name);
                            return(-1);
                        }
                    }
                    else
                    {
                        ExecutableType?toolType = this.ToolType;
                        if (toolType.HasValue)
                        {
                            toolType = this.ToolType;
                            result   = toolType.Value;
                        }
                    }
                    bool is64bit;
                    if ((result == ExecutableType.Native32Bit || result == ExecutableType.Native64Bit) && NativeMethodsShared.Is64bitApplication(str2, out is64bit))
                    {
                        result = is64bit ? ExecutableType.Native64Bit : ExecutableType.Native32Bit;
                    }
                    try
                    {
                        pathToTool1 = FileTracker.GetTrackerPath(result, this.TrackerSdkPath);
                        if (pathToTool1 == null)
                        {
                            this.Log.LogErrorFromResources("Error.MissingFile", (object)"tracker.exe");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ExceptionHandling.NotExpectedException(ex))
                        {
                            throw;
                        }
                        else
                        {
                            this.Log.LogErrorWithCodeFromResources("General.InvalidValue", (object)"TrackerSdkPath", (object)this.GetType().Name);
                            return(-1);
                        }
                    }
                    try
                    {
                        dllName = FileTracker.GetFileTrackerPath(result, this.TrackerFrameworkPath);
                    }
                    catch (Exception ex)
                    {
                        if (ExceptionHandling.NotExpectedException(ex))
                        {
                            throw;
                        }
                        else
                        {
                            this.Log.LogErrorWithCodeFromResources("General.InvalidValue", (object)"TrackerFrameworkPath", (object)this.GetType().Name);
                            return(-1);
                        }
                    }
                }
                else
                {
                    pathToTool1 = str2;
                }
                if (string.IsNullOrEmpty(pathToTool1))
                {
                    return(-1);
                }
                ErrorUtilities.VerifyThrowInternalRooted(pathToTool1);
                string commandLineCommands1;
                if (trackFileAccess)
                {
                    string str3 = FileTracker.TrackerArguments(str2, arguments, dllName, this.TrackerIntermediateDirectory, this.RootSource, this.CancelEventName);
                    this.Log.LogMessageFromResources(MessageImportance.Low, "Native_TrackingCommandMessage", new object[0]);
                    this.Log.LogMessage(MessageImportance.Low, pathToTool1 + (this.AttributeFileTracking ? " /a " : " ") + str3 + " " + responseFileCommands1, new object[0]);
                    str1 = FileUtilities.GetTemporaryFile();
                    using (StreamWriter streamWriter = new StreamWriter(str1, false, Encoding.Unicode))
                        streamWriter.Write(FileTracker.TrackerResponseFileArguments(dllName, this.TrackerIntermediateDirectory, this.RootSource, this.CancelEventName));
                    commandLineCommands1 = (this.AttributeFileTracking ? "/a @\"" : "@\"") + str1 + "\"" + FileTracker.TrackerCommandArguments(str2, arguments);
                }
                else
                {
                    commandLineCommands1 = arguments;
                }
                return(base.ExecuteTool(pathToTool1, responseFileCommands1, commandLineCommands1));
            }
            finally
            {
                if (str1 != null)
                {
                    this.DeleteTempFile(str1);
                }
            }
        }