Exemple #1
0
        /// <summary>
        /// Updates the current file number and starts its process.
        /// </summary>
        /// <param name="whichFile">Index of the fileList member to start processing.</param>
        private static void ActivateProcess(ZeroMunge sender, int whichFile)
        {
            // Don't advance to the next file if this is the last one
            if (whichFile > fileList.Count)
            {
                return;
            }
            activeFile = whichFile;
            MungeFactory target = fileList.ElementAt(whichFile);
            // Start & listen to the process on another thread to keep the UI thread responsive.
            Thread runProcThread = new Thread(() =>
                                              curProc = StartProcess(sender, target.FileDir, target.Args)
                                              );

            runProcThread.Name = "runProcThread: " + target.FileDir;
            runProcThread.Start();
        }
Exemple #2
0
        /// <summary>
        /// Use this to tell the manager when the active file has finished.
        /// </summary>
        /// <param name="sender">The sending ZeroMunge form.</param>
        /// <param name="whichFile">Index of the member in the fileList that finished.</param>
        /// <param name="singleFile">True, only process the first file in the list. False, process all files in the list.</param>
        private static void NotifyProcessComplete(ZeroMunge sender, int whichFile, bool singleFile)
        {
            try
            {
                MungeFactory target = fileList.ElementAt(whichFile);

                if (target.MungedFiles != null &&
                    target.MungedFiles.Count() > 0 &&
                    target.MungedFiles != null &&
                    target.MungedFiles[0] != "nil" &&
                    target.StagingDir != null &&
                    !target.FileDir.Contains("clean.bat") &&
                    target.CopyToStaging != null &&
                    sender.Platform == Platform.PC                     // only copy to staging area for the 'PC' Build
                    )
                {
                    if (target.CopyToStaging == "True")
                    {
                        // Copy the compiled files to the staging directory
                        List <string> filesToCopy = target.MungedFiles;

                        string sourceDir = target.MungeDir;
                        string targetDir = target.StagingDir;

                        // Copy each file to the staging directory
                        foreach (string file in filesToCopy)
                        {
                            // Assemble the full file paths
                            var fullSourceFilePath = string.Concat(sourceDir, "\\", file);
                            var fullTargetFilePath = string.Concat(targetDir, "\\", file);

                            // Remove any duplicate backslashes
                            fullSourceFilePath = fullSourceFilePath.Replace(@"\\", @"\");
                            fullTargetFilePath = fullTargetFilePath.Replace(@"\\", @"\");


                            // Make sure the source file exists before attempting to copy it
                            if (!File.Exists(fullSourceFilePath))
                            {
                                var message = string.Format("Source file does not exist at path: \"{0}\"", fullSourceFilePath);
                                Trace.WriteLine(message);
                                sender.Log(message, LogType.Error);
                            }
                            else
                            {
                                // Create the target directory if it doesn't already exist
                                if (!Directory.Exists(targetDir))
                                {
                                    try
                                    {
                                        Directory.CreateDirectory(targetDir);
                                    }
                                    catch (IOException e)
                                    {
                                        Trace.WriteLine(e.Message);
                                        sender.Log(e.Message, LogType.Error);
                                    }
                                    catch (UnauthorizedAccessException e)
                                    {
                                        Trace.WriteLine(e.Message);
                                        sender.Log(e.Message, LogType.Error);

                                        var message = "Try running the application with administrative privileges";
                                        Trace.WriteLine(message);
                                        sender.Log(message, LogType.Error);
                                    }
                                }

                                // Copy the file
                                if (File.Exists(fullSourceFilePath))
                                {
                                    try
                                    {
                                        File.Copy(fullSourceFilePath, fullTargetFilePath, true);

                                        var message = string.Format("Successfully copied \"{0}\" to \"{1}\"", fullSourceFilePath, fullTargetFilePath);
                                        Debug.WriteLine(message);
                                        sender.Log(message, LogType.Info);
                                    }
                                    catch (IOException e)
                                    {
                                        Trace.WriteLine(e.Message);
                                        sender.Log(e.Message, LogType.Error);
                                    }
                                    catch (UnauthorizedAccessException e)
                                    {
                                        Trace.WriteLine(e.Message);
                                        sender.Log(e.Message, LogType.Error);
                                    }
                                }
                                else
                                {
                                    var message = string.Format("File does not exist at path: \"{0}\"", fullSourceFilePath);
                                    Trace.WriteLine(message);
                                    sender.Log(message, LogType.Error);
                                }
                            }
                        }
                    }
                    else
                    {
                        var message = string.Format("Copy is unchecked, skipping copy operation for \"{0}\"", target.FileDir);
                        Debug.WriteLine(message);
                        sender.Log(message, LogType.Warning);
                    }
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                var message = "ArgumentOutOfRangeException! Reason: " + e.Message;
                Trace.WriteLine(message);
                sender.Log(message, LogType.Error);
            }

            // Are we processing multiple files?
            if (!singleFile)
            {
                // If we've reached here, then all the processes are complete
                if (activeFile >= (fileList.Count - 1))
                {
                    // We have no more files, so finish up
                    Complete(sender);
                }
                else
                {
                    // Move on to the next file
                    ActivateProcess(sender, activeFile + 1);
                }
            }
            else
            {
                // We have no more files, so finish up
                Complete(sender);
            }
        }