Example #1
0
        /// <summary>
        /// Creates a new task and returns a copy instance
        /// </summary>
        /// <param name="parentBNK">Parent BNK file</param>
        /// <param name="packedFilePath">Path of packed file under edit</param>
        /// <param name="isFurtive">true to prevent this task to be displayed in GUI, else false</param>
        /// <returns>Added task instance</returns>
        public Task AddTask(BNK parentBNK, string packedFilePath, bool isFurtive)
        {
            Task editTask = new Task();

            if (parentBNK == null)
            {
                return(editTask);
            }

            // New task
            editTask.parentBNK            = parentBNK;
            editTask.editedPackedFilePath = packedFilePath;
            editTask.startDate            = DateTime.Now;

            if (_SameTaskExists(editTask))
            {
                throw new Exception(ERROR_CODE_TASK_EXISTS);
            }

            // Preparing edit...
            editTask.isFurtive     = isFurtive;
            editTask.extractedFile = _PrepareFile(editTask);

            if (editTask.extractedFile == null)
            {
                throw new Exception(ERROR_CODE_EXTRACT_FAILED);
            }

            // BUG_48: Preparing tracking...
            editTask.trackedFile = TduFile.GetTrackedFileName(editTask.extractedFile);

            // Original write time
            if (editTask.extractedFile.Equals(editTask.trackedFile))
            {
                FileInfo fi = new FileInfo(editTask.extractedFile);

                editTask.trackedLastFileWriteTime = fi.LastWriteTime;
            }
            else
            {
                // If tracked file name is different from extracted one, this data is set after first tracking
                // Because at the moment tracked file may not be ready
                editTask.trackedLastFileWriteTime = DateTime.MinValue;
            }

            editTask.isValid = true;

            // Change in task list
            _Tasks.Add(editTask);
            NotifyAll();

            return(editTask);
        }