Exemple #1
0
        /// <summary>
        /// ToDo: update for new design
        /// Set an action based on user choice and perform action to specified file
        /// This action is stream (file content) editing for the file. Right now,
        /// following caveats are not taken into account,
        ///  Unmanageable file size: >= 1 GB, check read files (API in msdn) limit
        /// Actions:
        /// - Replace Tabs
        /// - Do all styling to apply modern format in source code
        /// </summary>
        private void ProcessFile(string filePath)
        {
            var ext = new DirectoryInfo(filePath).Extension.Substring(1);

            if (IsInExclusionList(filePath, ext))
            {
                Console.WriteLine(" [Ignored] " + GetSimplifiedPath(filePath));
                return;
            }
            FileInfo.Init(filePath);
            if (ShouldReplaceTabs)
            {
                ReplaceTabs();
            }
            FileInfo.ReadFile();
            if (ShouldIndent)
            {
                Indent();
            }
            FixDocumentation();
            if (FileInfo.IsModified)
            {
                Console.WriteLine(" " + GetSimplifiedPath(FileInfo.Path) + ": " + FileInfo.ModInfo);
                ModifiedFileCount++;
                ExtList.Add(ext);
                if (!ShouldSimulate)
                {
                    FileInfo.WriteFile();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// ToDo: update for new design
        /// Set an action based on user choice and perform action to specified file
        /// </summary>
        private async Task ProcessFile(string filePath)
        {
            if (!System.IO.Path.HasExtension(filePath))
            {
                Console.WriteLine("File does not have an extension!");
                mFileInfo.Update("Fail: has no extension");
                return;
            }

            // If verbose
            // Console.WriteLine("Processing File " + filePath + ":");
            mFileInfo.Init(filePath);

            // we don't need this var: IsSingleStaged anymore
            if (!IsSingleStaged)
            {
                foreach (CONVERTSTAGE stage in (CONVERTSTAGE[])Enum.GetValues(typeof(CONVERTSTAGE)))
                {
                    Stage = stage;
                    if (mFileInfo.IsInError)
                    {
                        break;
                    }

                    switch (Stage)
                    {
                    case CONVERTSTAGE.ExtractArchive:
                        ExtractRar(filePath);
                        break;

                    case CONVERTSTAGE.RenameFile:
                        RenameFile();
                        break;

                    case CONVERTSTAGE.ExtractMedia:
                        // accept containers containing subrip: currently only mkv
                        if (IsSupportedMedia(mFileInfo.Path) && (!ShouldSimulate || !mFileInfo.ModInfo.Contains("extract")))
                        {
                            // extract already checked for it
                            if (!mFileInfo.ModInfo.Contains("extract"))
                            {
                                HasEnoughFreeSpace((new System.IO.FileInfo(mFileInfo.Path)).Length);
                            }
                            if (mFileInfo.IsInError)
                            {
                                break;
                            }

                            var extractSub = new FFMpegUtil(ref mFileInfo);
                            mFileInfo = await extractSub.Run(ShouldSimulate);
                        }
                        break;

                    case CONVERTSTAGE.CreateArchive:
                        break;

                    default:
                        throw new InvalidOperationException("Invalid argument " + Stage + " to ProcessFile::switch");
                    }
                }
            }

            if (mFileInfo.IsInError)
            {
                FailedFileCount++;
            }
            else if (mFileInfo.IsModified)
            {
                ModifiedFileCount++;
            }
        }