示例#1
0
        private bool ExportFile(string filePath, string suffix)
        {
            if (!_Realm.Packs.TryGetFile(filePath, out var file))
            {
                return(false);
            }

            var scdFile = new Sound.ScdFile(file);
            var count   = 0;

            for (var i = 0; i < scdFile.ScdHeader.EntryCount; ++i)
            {
                var e = scdFile.Entries[i];
                if (e == null)
                {
                    continue;
                }

                var fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filePath);
                if (suffix != null)
                {
                    fileNameWithoutExtension += "-" + suffix;
                }
                if (++count > 1)
                {
                    fileNameWithoutExtension += "-" + count;
                }

                foreach (var invalidChar in System.IO.Path.GetInvalidFileNameChars())
                {
                    fileNameWithoutExtension = fileNameWithoutExtension.Replace(invalidChar.ToString(), "");
                }

                var targetPath = System.IO.Path.Combine(_Realm.GameVersion, System.IO.Path.GetDirectoryName(filePath), fileNameWithoutExtension);

                switch (e.Header.Codec)
                {
                case Sound.ScdCodec.MSADPCM:
                    targetPath += ".wav";
                    break;

                case Sound.ScdCodec.OGG:
                    targetPath += ".ogg";
                    break;

                default:
                    throw new NotSupportedException();
                }

                var fInfo = new System.IO.FileInfo(targetPath);

                if (!fInfo.Directory.Exists)
                {
                    fInfo.Directory.Create();
                }
                System.IO.File.WriteAllBytes(fInfo.FullName, e.GetDecoded());
            }

            return(true);
        }
        public override async Task<bool> InvokeAsync(string paramList) {
            var bgms = _Realm.GameData.GetSheet("BGM");

            var successCount = 0;
            var failCount = 0;
            foreach (Xiv.IXivRow bgm in bgms) {
                var filePath = bgm["File"].ToString();

                try {

                    if (string.IsNullOrWhiteSpace(filePath))
                        continue;

                    IO.File file;

                    if (_Realm.Packs.TryGetFile(filePath, out file)) {

                        var scdFile = new Sound.ScdFile(file);
                        for (var i = 0; i < scdFile.ScdHeader.EntryCount; ++i) {
                            var e = scdFile.Entries[i];
                            if (e == null)
                                continue;

                            var targetPath = System.IO.Path.Combine(_Realm.GameVersion, filePath + "-" + i.ToString());

                            switch (e.Header.Codec) {
                                case Sound.ScdCodec.MSADPCM:
                                    targetPath += ".wav";
                                    break;
                                case Sound.ScdCodec.OGG:
                                    targetPath += ".ogg";
                                    break;
                                default:
                                    throw new NotSupportedException();
                            }

                            var fInfo = new System.IO.FileInfo(targetPath);
                            
                            if (!fInfo.Directory.Exists)
                                fInfo.Directory.Create();
                            System.IO.File.WriteAllBytes(fInfo.FullName, e.GetDecoded());
                        }

                        ++successCount;
                    } else {
                        OutputError("File {0} not found.", filePath);
                        ++failCount;
                    }
                } catch(Exception e) {
                    OutputError("Export of {0} failed: {1}", filePath, e.Message);
                    ++failCount;
                }
            }
            OutputInformation("{0} files exported, {1} failed", successCount, failCount);

            return true;
        }
示例#3
0
        private bool ExportFile(string filePath, string suffix) {
            IO.File file;

            if (!_Realm.Packs.TryGetFile(filePath, out file))
                return false;

            var scdFile = new Sound.ScdFile(file);
            var count = 0;
            for (var i = 0; i < scdFile.ScdHeader.EntryCount; ++i) {
                var e = scdFile.Entries[i];
                if (e == null)
                    continue;

                var fileNameWithoutExtension = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filePath), System.IO.Path.GetFileNameWithoutExtension(filePath));
                if (suffix != null)
                    fileNameWithoutExtension += "-" + suffix;
                if (++count > 1)
                    fileNameWithoutExtension += "-" + count;

                var targetPath = System.IO.Path.Combine(_Realm.GameVersion, fileNameWithoutExtension);

                switch (e.Header.Codec) {
                    case Sound.ScdCodec.MSADPCM:
                        targetPath += ".wav";
                        break;
                    case Sound.ScdCodec.OGG:
                        targetPath += ".ogg";
                        break;
                    default:
                        throw new NotSupportedException();
                }

                var fInfo = new System.IO.FileInfo(targetPath);

                if (!fInfo.Directory.Exists)
                    fInfo.Directory.Create();
                System.IO.File.WriteAllBytes(fInfo.FullName, e.GetDecoded());
            }

            return true;
        }
示例#4
0
        public override async Task <bool> InvokeAsync(string paramList)
        {
            var bgms = _Realm.GameData.GetSheet("BGM");

            var successCount = 0;
            var failCount    = 0;

            foreach (Xiv.IXivRow bgm in bgms)
            {
                var filePath = bgm["File"].ToString();

                try {
                    if (string.IsNullOrWhiteSpace(filePath))
                    {
                        continue;
                    }

                    IO.File file;

                    if (_Realm.Packs.TryGetFile(filePath, out file))
                    {
                        var scdFile = new Sound.ScdFile(file);
                        for (var i = 0; i < scdFile.ScdHeader.EntryCount; ++i)
                        {
                            var e = scdFile.Entries[i];
                            if (e == null)
                            {
                                continue;
                            }

                            var targetPath = System.IO.Path.Combine(_Realm.GameVersion, filePath + "-" + i.ToString());

                            switch (e.Header.Codec)
                            {
                            case Sound.ScdCodec.MSADPCM:
                                targetPath += ".wav";
                                break;

                            case Sound.ScdCodec.OGG:
                                targetPath += ".ogg";
                                break;

                            default:
                                throw new NotSupportedException();
                            }

                            var fInfo = new System.IO.FileInfo(targetPath);

                            if (!fInfo.Directory.Exists)
                            {
                                fInfo.Directory.Create();
                            }
                            System.IO.File.WriteAllBytes(fInfo.FullName, e.GetDecoded());
                        }

                        ++successCount;
                    }
                    else
                    {
                        OutputError("File {0} not found.", filePath);
                        ++failCount;
                    }
                } catch (Exception e) {
                    OutputError("Export of {0} failed: {1}", filePath, e.Message);
                    ++failCount;
                }
            }
            OutputInformation("{0} files exported, {1} failed", successCount, failCount);

            return(true);
        }