Example #1
0
        public void Export()
        {
            try
            {
                String exportPath = ExportPath;
                if (File.Exists(exportPath))
                {
                    Log.Warning($"[{TypeName}] Export was skipped bacause a file already exists: [{exportPath}].");
                    return;
                }

                Log.Message($"[{TypeName}] Exporting...");

                TxtEntry[] abilities = PrepareEntries();

                FileCommander.PrepareFileDirectory(exportPath);
                TxtWriter.WriteStrings(exportPath, abilities);

                Log.Message($"[{TypeName}] Exporting completed successfully.");
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"[{TypeName}] Failed to export resource.");
            }
        }
Example #2
0
        private static void ExportSoundSafe(String akbOutputPath, TextAsset textAsset)
        {
            try
            {
                String oggOutputPath = akbOutputPath + ".ogg";

                String fileName;
                String directoryPath;
                String alternativePath;
                if (AudioResources.TryAppendDisplayName(akbOutputPath, out directoryPath, out fileName, out alternativePath))
                {
                    alternativePath += ".ogg";

                    if (File.Exists(alternativePath))
                    {
                        Log.Warning("[AudioResourceExporter] Export was skipped bacause a file already exists: [{0}].", alternativePath);
                        return;
                    }

                    if (File.Exists(oggOutputPath))
                    {
                        Log.Message("[AudioResourceExporter] The file [{0}] will be renamed to [{1}].", oggOutputPath, alternativePath);
                        File.Move(oggOutputPath, alternativePath);
                        Log.Warning("[AudioResourceExporter] Export was skipped bacause a file already exists: [{0}].", alternativePath);
                        return;
                    }

                    oggOutputPath = alternativePath;
                }
                else if (File.Exists(akbOutputPath))
                {
                    Log.Warning("[AudioResourceExporter] Export was skipped bacause a file already exists: [{0}].", akbOutputPath);
                    return;
                }
                else
                {
                    oggOutputPath = akbOutputPath + ".ogg";
                }

                FileCommander.PrepareFileDirectory(akbOutputPath);

                using (Stream akb = File.Create(akbOutputPath))
                    using (Stream ogg = File.Create(oggOutputPath))
                    {
                        akb.Write(textAsset.bytes, 0, textAsset.bytes.Length);
                        ogg.Write(textAsset.bytes, 304, textAsset.bytes.Length - 304);
                    }

                File.SetLastWriteTimeUtc(akbOutputPath, File.GetLastWriteTimeUtc(oggOutputPath));
            }
            catch (Exception ex)
            {
                Log.Error(ex, "[AudioResourceExporter] Failed to export sound [{0}] to the [{1}].", textAsset.name, akbOutputPath);
            }
        }