LongoMatch.Services.ProjectsManager.RemuxOutputFile C# (CSharp) Method

RemuxOutputFile() private method

private RemuxOutputFile ( EncodingSettings settings ) : void
settings EncodingSettings
return void
        void RemuxOutputFile(EncodingSettings settings)
        {
            VideoMuxerType muxer;

            /* We need to remux to the original format */
            muxer = settings.EncodingProfile.Muxer;
            if (muxer == VideoMuxerType.Avi || muxer == VideoMuxerType.Mp4) {
                string outFile = settings.OutputFile;
                string tmpFile = settings.OutputFile;

                while (File.Exists (tmpFile)) {
                    tmpFile = tmpFile + ".tmp";
                }

                Log.Debug ("Remuxing file tmp: " + tmpFile + " out: " + outFile);

                try {
                    File.Move (outFile, tmpFile);
                } catch (Exception ex) {
                    /* Try to fix "Sharing violation on path" in windows
                     * wait a bit more until the file lock is released */
                    Log.Exception (ex);
                    System.Threading.Thread.Sleep (5 * 1000);
                    try {
                        File.Move (outFile, tmpFile);
                    } catch (Exception ex2) {
                        Log.Exception (ex2);
                        /* It failed again, just skip remuxing */
                        return;
                    }
                }

                /* Remuxing suceed, delete old file */
                if (guiToolkit.RemuxFile (tmpFile, outFile, muxer) == outFile) {
                    System.IO.File.Delete (tmpFile);
                } else {
                    System.IO.File.Delete (outFile);
                    System.IO.File.Move (tmpFile, outFile);
                }
            }
        }