Beispiel #1
0
 private BplDocumentParser _invokeParser(BplFormat format, string input) {
    BplDocumentParser parser = null;
    switch (format) {
       case BplFormat.Xml:
          parser = new BplXmlParser { PreserveErrorsInfo = true };
          break;
       case BplFormat.Json:
          parser = new BplJsonParser { PreserveErrorsInfo = true, StronglyTyped = false };
          break;
       case BplFormat.Json_t:
          parser = new BplJsonParser { PreserveErrorsInfo = true, StronglyTyped = true };
          break;
       case BplFormat.Binary:
          parser = new BplHexParser { };
          break;
       default:
          return null;
    }
    if (parser != null) {
       parser.Parse(input);
    }
    return parser;
 }
Beispiel #2
0
      private bool _saveFile(bool saveAs) {
         var path = _replaceExtension(InputFile, OutputFormat);
         if (path.IsEmpty() || saveAs) {
            path = FileDialogs.ChooseFileToSave(Shell.UserDataFolder, "Save BPL File" + (saveAs ? " As" : ""), _bplFileFilter);
            if (path.IsEmpty()) return false;
            InputFile = _replaceExtension(path, InputFormat);
         }

         var success = false;
         try {
            if (OutputFormat == BplFormat.Binary) {
               var parser = new BplHexParser();
               parser.Parse(_output.Text);
               var writer = new BplBinaryWriter();
               writer.Serialize(parser.Output);
               File.WriteAllBytes(path, writer.ToByteArray());
            } else {
               File.WriteAllText(path, _output.Text);
            }
            IsDirty = false;
            success = true;
         } catch (Exception e) {
            MessageBox.Show("Failed to save '{0}' file. {1}".Substitute(path, e.Message));
         }
         return success;
      }