Esempio n. 1
0
        public async Task UpdateAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Checking Realm Version...");
            var gameVer = RealmReversed.GameVersion;
            var defVer  = RealmReversed.DefinitionVersion;
            var updates = $"Game Version: {gameVer}\r\nDefinition Version: {defVer}.";

            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(updates));
            _logger.LogInformation($"Game Version: {gameVer}. Definition Version: {defVer}.");
            if (!RealmReversed.IsCurrentVersion)
            {
                _logger.LogInformation("Updating Realm.");
                IProgress <UpdateProgress> value = new ProgressReporter(_logger);
                const bool IncludeDataChanges    = true;
                var        updateReport          = await Task.Run(() => RealmReversed.Update(IncludeDataChanges, value), cancellationToken);

                foreach (var change in updateReport.Changes)
                {
                    updates = await Task.Run(() => $"{value}\r\n{change.SheetName} {change.ChangeType}");

                    _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(updates));
                    _logger.LogInformation(updates);
                }
            }
            else
            {
                updates = "Running current version.";
                _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(updates));
                _logger.LogInformation(updates);
            }
        }
        public async Task ConvertToScdAsync(string[] currentOggFiles, CancellationToken cancellationToken)
        {
            var processed = 0;
            var failed    = 0;

            foreach (var file in currentOggFiles)
            {
                try
                {
                    await Task.Run(() => Convert(file));

                    processed++;
                    var scdFile = file.Contains(".scd.ogg") ? file.Replace(".ogg", "") : file.Replace(".ogg", ".scd");
                    _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{new FileInfo(scdFile).Name} created"));
                }
                catch (Exception ex)
                {
                    var message = $"There was a problem converting {file}.";
                    _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{message}\r\n{ex.Message}."));
                    _logger.LogError(ex, message);
                    failed++;
                }
            }
            var result = $"Completed SCD Conversion. {processed} converted. {failed} failed.";

            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{result}"));
            _logger.LogInformation(result);
        }
        public async Task GetWeatherAsync(DateTime dateTime, IEnumerable <string> zones, int forcastIntervals, CancellationToken cancellationToken)
        {
            if (zones == null)
            {
                foreach (var territory in _territoryList)
                {
                    var eorzeaDateTime = new EorzeaDateTime(dateTime);
                    var zone           = territory.PlaceName;
                    for (var i = 0; i < forcastIntervals; i++)
                    {
                        var weather = await Task.Run(() => territory.WeatherRate.Forecast(eorzeaDateTime).Name, cancellationToken);

                        //var localTime = eorzeaDateTime.GetRealTime().ToLocalTime();
                        _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{zone} - {weather}"));
                        eorzeaDateTime = Increment(eorzeaDateTime);
                    }
                }
            }
            else
            {
                foreach (var zone in zones)
                {
                    var eorzeaDateTime = new EorzeaDateTime(dateTime);

                    for (var i = 0; i < forcastIntervals; i++)
                    {
                        var weather = await Task.Run(() => _territoryList.FirstOrDefault(_ => _.PlaceName.ToString() == zone).WeatherRate.Forecast(eorzeaDateTime).Name, cancellationToken);

                        var localTime = eorzeaDateTime.GetRealTime().ToLocalTime();
                        _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{eorzeaDateTime}({localTime}): {zone} - {weather}"));
                        eorzeaDateTime = Increment(eorzeaDateTime);
                    }
                }
            }
        }
Esempio n. 4
0
        public void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 192)
        {
            using var reader = new AudioFileReader(waveFileName);
            using var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate);
            reader.CopyTo(writer);
            var message = $"{mp3FileName} created.";

            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(message));
            _logger.LogInformation(message);
        }
Esempio n. 5
0
        public async Task ConvertToWavAsync(IEnumerable <string> oggFiles, CancellationToken cancellationToken)
        {
            int processed = 0, skipped = 0, failed = 0;

            foreach (var oggFile in oggFiles)
            {
                var folder       = Path.GetDirectoryName(oggFile);
                var parentFolder = Directory.GetParent(folder);
                var wavFolder    = Path.Combine(parentFolder.FullName, "WAV");

                if (!Directory.Exists(wavFolder))
                {
                    Directory.CreateDirectory(wavFolder);
                }

                var wavFile = Path.Combine(wavFolder, Path.GetFileName(oggFile).Replace(".ogg", ".wav"));

                if (File.Exists(wavFile))
                {
                    var skipMessage = await Task.Run(() => $"{wavFile} exists. Skipping.");

                    _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(skipMessage));
                    _logger.LogInformation(skipMessage);
                    skipped++;
                    continue;
                }

                try
                {
                    await ConvertAsync(oggFile, wavFile);

                    processed++;
                }
                catch (Exception ex)
                {
                    var errorMessage = $"Unable to convert {oggFile}";
                    _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(errorMessage));
                    _logger.LogError(ex, errorMessage);
                    failed++;
                }
            }
            var message = $"Completed WAV Conversion. {processed} converted. {skipped} skipped. {failed} failed.";

            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(message));
            _logger.LogInformation(message);
        }
Esempio n. 6
0
        public List <string> ExportSchema()
        {
            var imports = new List <string>();

            // .Where(n => !n.Contains("quest/") && !n.Contains("custom/"))
            foreach (var name in _realm.RealmReversed.GameData.AvailableSheets)
            {
                var sheet   = _realm.RealmReversed.GameData.GetSheet(name);
                var variant = sheet.Header.Variant;
                var sheet2  = sheet as XivSheet2 <XivSubRow>;

                _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"Sheet: {name}, variant: {variant}"));
                _logger.LogInformation($"Sheet: {name}, variant: {variant}");

                if (sheet.Count == 0)
                {
                    continue;
                }

                var sb = new StringBuilder();

                sb.AppendLine($"CREATE TABLE {GetTableName(sheet)} (");

                // key meme
                sb.AppendLine($"\t[_Key] INT NOT NULL,");
                if (sheet.Header.Variant != 1)
                {
                    sb.AppendLine($"\t[_SubKey] INT NOT NULL,");
                }

                // add cols
                foreach (var column in sheet.Header.Columns)
                {
                    var colName = column.Name;
                    if (string.IsNullOrEmpty(colName))
                    {
                        colName = $"unk{column.Index}";
                    }

                    sb.AppendLine($"\t[{colName.Replace("[", "{").Replace("]", "}")}] {GetSqlType(column.Reader.Type)} NULL,");
                }

                // primary key
                sb.AppendLine($"PRIMARY KEY CLUSTERED (");
                sb.AppendLine(sheet.Header.Variant == 1 ? $"\t[_Key] ASC" : $"\t[_Key] ASC, [_SubKey] ASC");
                sb.AppendLine("))");

                sb.AppendLine("GO");
                sb.AppendLine();

                // Write data
                WriteRows(sheet, sb);

                sb.AppendLine("GO");
                sb.AppendLine();

                imports.Add(sb.ToString());
            }

            return(imports);
        }
Esempio n. 7
0
        public List <string> ExportSchema()
        {
            var imports = new List <string>();

            // .Where(n => !n.Contains("quest/") && !n.Contains("custom/"))
            foreach (var name in _realm.RealmReversed.GameData.AvailableSheets)
            {
                var sheet   = _realm.RealmReversed.GameData.GetSheet(name);
                var variant = sheet.Header.Variant;
                var sheet2  = sheet as XivSheet2 <XivSubRow>;

                _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"Sheet: {name}, variant: {variant}"));
                _logger.LogInformation($"Sheet: {name}, variant: {variant}");

                if (sheet.Count == 0)
                {
                    continue;
                }

                var sb = new StringBuilder();

                sb.AppendLine($"CREATE TABLE {GetTableName(sheet)} (");

                // key meme
                if (sheet.Header.Variant == 1)
                {
                    sb.AppendLine($"  `_Key` INT NOT NULL,");
                }
                else
                {
                    sb.AppendLine($"  `_Key` INT NOT NULL,");
                    sb.AppendLine($"  `_SubKey` INT NOT NULL,");
                }

                // add cols
                foreach (var column in sheet.Header.Columns)
                {
                    var colName = column.Name;
                    if (string.IsNullOrEmpty(colName))
                    {
                        colName = $"unk{column.Index}";
                    }

                    sb.AppendLine($"  `{colName}` {GetSqlType(column.Reader.Type)},");
                }

                // primary key
                if (sheet.Header.Variant == 1)
                {
                    sb.AppendLine($"  PRIMARY KEY (`_Key`)");
                }
                else
                {
                    sb.AppendLine($"  PRIMARY KEY (`_Key`, `_SubKey`)");
                }

                sb.AppendLine(") COLLATE='utf8mb4_unicode_ci' ENGINE=MyISAM;");
                sb.AppendLine();

                WriteRows(sheet, sb);

                imports.Add(sb.ToString());
            }

            return(imports);
        }
        public async Task GetFilesAsync(CancellationToken cancellationToken)
        {
            var files = _realm.GameData.GetSheet("BGM");
            int success = 0, fail = 0;

            foreach (IXivRow file in files)
            {
                var path = file["File"].ToString();

                if (string.IsNullOrWhiteSpace(path))
                {
                    continue;
                }
                else
                {
                    try
                    {
                        if (await Task.Run(() => ExportFile(path, null)))
                        {
                            var successMessage = $"{path} exported.";
                            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(successMessage));
                            _logger.LogInformation(successMessage);
                            success++;
                        }
                        else
                        {
                            var notFoundMessage = $"File {path} not found.";
                            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(notFoundMessage));
                            _logger.LogInformation(notFoundMessage);
                            fail++;
                        }
                    }
                    catch (Exception ex)
                    {
                        var errorMessage = $"Could not export {path}.";
                        _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(errorMessage));
                        _logger.LogError(ex, errorMessage);
                        fail++;
                    }
                }
            }

            var orch     = _realm.GameData.GetSheet("Orchestrion");
            var orchPath = _realm.GameData.GetSheet("OrchestrionPath");

            foreach (IXivRow orchInfo in orch)
            {
                var path     = orchPath[orchInfo.Key];
                var name     = orchInfo["Name"].ToString();
                var filePath = path["File"].ToString();

                if (string.IsNullOrWhiteSpace(filePath))
                {
                    continue;
                }
                else
                {
                    try
                    {
                        if (await Task.Run(() => ExportFile(filePath, name)))
                        {
                            var successMessage = $"{filePath}-{name} exported.";
                            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(successMessage));
                            _logger.LogInformation(successMessage);
                            success++;
                        }
                        else
                        {
                            var notFoundMessage = $"File {filePath}-{name} not found.";
                            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(notFoundMessage));
                            _logger.LogInformation(notFoundMessage);
                            fail++;
                        }
                    }
                    catch (Exception ex)
                    {
                        var errorMessage = $"Could not export {filePath}-{name}.";
                        _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(errorMessage));
                        _logger.LogError(ex, errorMessage);
                        fail++;
                    }
                }
            }

            var message = $"{success} files exported. {fail} files failed.";

            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(message));
            _logger.LogInformation(message);
        }
Esempio n. 9
0
        public async Task RipAsync(string paramList, CancellationToken cancellationToken)
        {
            const string csvFileFormat = "exd-all/{0}{1}.csv";
            var          arr           = _realm.RealmReversed;

            IEnumerable <string> filesToExport;

            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"Getting sheet list..."));
            _logger.LogInformation("Getting sheet list...");
            if (string.IsNullOrWhiteSpace(paramList))
            {
                filesToExport = arr.GameData.AvailableSheets;
            }
            else
            {
                filesToExport = paramList.Split(' ').Select(_ => arr.GameData.FixName(_));
            }

            var successCount = 0;
            var failCount    = 0;

            foreach (var name in filesToExport)
            {
                var sheet    = arr.GameData.GetSheet(name);
                var language = _realm.RealmReversed.GameData.ActiveLanguage == Language.None ? sheet.Header.AvailableLanguages : new List <Language> {
                    _realm.RealmReversed.GameData.ActiveLanguage
                };
                foreach (var lang in language /*sheet.Header.AvailableLanguages*/)
                {
                    var code = lang.GetCode();
                    if (code.Length > 0)
                    {
                        code = "." + code;
                    }
                    var target = new FileInfo(Path.Combine(arr.GameVersion, string.Format(csvFileFormat, name, code)));
                    try
                    {
                        if (!target.Directory.Exists)
                        {
                            target.Directory.Create();
                        }

                        await Task.Run(() => ExdHelper.SaveAsCsv(sheet, lang, target.FullName, false));

                        _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs($"{target.Name}"));
                        _logger.LogInformation($"Exported {target.Name}.");
                        ++successCount;
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, $"Export of {target.Name} failed.");
                        try
                        {
                            if (target.Exists)
                            {
                                target.Delete();
                            }
                        }
                        catch { }
                        ++failCount;
                    }
                }
            }
            var returnValue = $"{successCount} files exported, {failCount} failed";

            _logger.LogInformation(returnValue);
            _sendMessageEvent.OnSendMessageEvent(new SendMessageEventArgs(returnValue));
        }