Commit() public method

public Commit ( ) : void
return void
Example #1
0
        internal async static Task Copy(CancellationToken cancel, string source, string dest)
        {
            if (cancel.IsCancellationRequested)
            {
                return;
            }

            using (new LogScope(log, "Copy {0} to {1}", source, dest))
            {
                if (Directory.Exists(source))
                {
                    var d = new DirectoryInfo(source);
                    EnsureDirectoryExists(dest);
                    foreach (var c in d.GetFileSystemInfos())
                    {
                        await Copy(cancel, c.FullName, Path.Combine(dest, c.Name));
                    }
                }
                else
                {
                    var si       = new FileInfo(source);
                    var di       = new FileInfo(dest);
                    var needCopy = !di.Exists || (si.LastWriteTimeUtc != di.LastWriteTimeUtc) || (si.Length != di.Length);
                    if (needCopy)
                    {
                        using (var t = new FileTransaction(dest))
                        {
                            using (var r = File.OpenRead(source))
                                using (var w = File.OpenWrite(t.TempPath))
                                {
                                    await r.CopyToAsync(w, 0x10000, cancel);
                                }
                            t.Commit();
                        }
                    }
                }
            }
        }
Example #2
0
        public async static Task AudioFileToTipToiAudioFile(CancellationToken cancellationToken, string sourceFile, string oggDestinationFile)
        {
            using (new LogScope(log, "Convert {0} to {1}", sourceFile, oggDestinationFile))
            {
                using (var t = new FileTransaction(oggDestinationFile))
                {
                    var ext     = Path.GetExtension(sourceFile).ToLowerInvariant();
                    var wavFile = oggDestinationFile + ".wav";
                    try
                    {
                        switch (ext)
                        {
                        case mp3Extension:
                        {
                            await SubProcess.CheckedCall(cancellationToken
                                                         , "mpg123.exe",
                                                         "-w", wavFile.Quote(),
                                                         sourceFile.Quote());

                            bool isMono = true;

                            await SubProcess.CheckedCall(cancellationToken,
                                                         "oggenc2.exe",
                                                         wavFile.Quote(),
                                                         ("--output=" + t.TempPath).Quote(),
                                                         "--resample", "22500",
                                                         "--quiet",
                                                         isMono?null : "--downmix"
                                                         );
                        }
                        break;

                        case oggExtension:
                        {
                            bool isMono = GetIsMonoFromOggdecOutput(await SubProcess.GetOutput(cancellationToken
                                                                                               , "oggdec.exe",
                                                                                               "--wavout", wavFile.Quote(),
                                                                                               "-q",
                                                                                               sourceFile.Quote()));

                            await SubProcess.CheckedCall(cancellationToken,
                                                         "oggenc2.exe",
                                                         wavFile.Quote(),
                                                         ("--output=" + t.TempPath).Quote(),
                                                         "--resample", "22500",
                                                         "--quiet",
                                                         isMono?null : "--downmix"
                                                         );
                        }
                        break;

                        case wavExtension:
                        {
                            await SubProcess.CheckedCall(cancellationToken,
                                                         "oggenc2.exe",
                                                         sourceFile.Quote(),
                                                         "-o", t.TempPath.Quote(),
                                                         "--quiet",
                                                         "--resample", "22500",
                                                         "--downmix");
                        }
                        break;

                        default:
                            throw new ArgumentOutOfRangeException("sourceFile", sourceFile, "File type is not supported.");
                        }
                    }
                    finally
                    {
                        PathUtil.EnsureFileNotExists(wavFile);
                    }

                    t.Commit();
                }
            }
        }
Example #3
0
        public async static Task AudioFileToTipToiAudioFile(CancellationToken cancellationToken, string sourceFile, string oggDestinationFile)
        {
            using (new LogScope(log, "Convert {0} to {1}", sourceFile, oggDestinationFile))
            {
                using (var t = new FileTransaction(oggDestinationFile))
                {
                    var ext = Path.GetExtension(sourceFile).ToLowerInvariant();
                    var wavFile = oggDestinationFile + ".wav";
                    try
                    {
                        switch (ext)
                        {
                            case mp3Extension:
                                {
                                    await SubProcess.CheckedCall(cancellationToken
                                        , "mpg123.exe",
                                        "-w", wavFile.Quote(),
                                        sourceFile.Quote());

                                    bool isMono = true;

                                    await SubProcess.CheckedCall(cancellationToken,
                                        "oggenc2.exe",
                                        wavFile.Quote(),
                                        ("--output=" + t.TempPath).Quote(),
                                        "--resample", "22500",
                                        "--quiet",
                                        isMono ? null : "--downmix"
                                        );
                                }
                                break;
                            case oggExtension:
                                {
                                    bool isMono = GetIsMonoFromOggdecOutput(await SubProcess.GetOutput(cancellationToken
                                        , "oggdec.exe",
                                        "--wavout", wavFile.Quote(),
                                        "-q",
                                        sourceFile.Quote()));

                                    await SubProcess.CheckedCall(cancellationToken,
                                        "oggenc2.exe",
                                        wavFile.Quote(),
                                        ("--output=" + t.TempPath).Quote(),
                                        "--resample", "22500",
                                        "--quiet",
                                        isMono ? null : "--downmix"
                                        );
                                }
                                break;
                            case wavExtension:
                                {
                                    await SubProcess.CheckedCall(cancellationToken,
                                        "oggenc2.exe",
                                        sourceFile.Quote(),
                                        "-o", t.TempPath.Quote(),
                                        "--quiet",
                                        "--resample", "22500",
                                        "--downmix");
                                }
                                break;
                            default:
                                throw new ArgumentOutOfRangeException("sourceFile", sourceFile, "File type is not supported.");
                        }
                    }
                    finally
                    {
                        PathUtil.EnsureFileNotExists(wavFile);
                    }

                    t.Commit();
                }
            }
        }