void FFmpegPresets::ExportPresets(wxString &filename)
{
   XMLFileWriter writer;
   writer.Open(filename,wxT("wb"));
   WriteXMLHeader(writer);
   WriteXML(writer);
}
示例#2
0
void KeyConfigPrefs::OnSave(wxCommandEvent& event)
{
   Apply();

   wxString fName = wxT("Audacity-keys.xml");
   wxString path = gPrefs->Read(wxT("/DefaultExportPath"),
                                ::wxGetCwd());

   fName = FileSelector(_("Export Keyboard Shortcuts As:"),
                        NULL,
                        fName,
                        wxT("xml"),
                        wxT("*.xml"), wxSAVE | wxOVERWRITE_PROMPT, this);

   if (!fName)
      return;

   path = wxPathOnly(fName);
   gPrefs->Write(wxT("/DefaultExportPath"), path);

   XMLFileWriter prefFile;
   
   prefFile.Open(fName, wxT("wb"));

   if (!prefFile.IsOpened()) {
      wxMessageBox(_("Couldn't write to file: ") + fName,
                   _("Error saving keyboard shortcuts"),
                   wxOK | wxCENTRE, this);
      return;
   }

   mManager->WriteXML(prefFile);

   prefFile.Close();
}
FFmpegPresets::~FFmpegPresets()
{
   XMLFileWriter writer;
   wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
   writer.Open(xmlFileName.GetFullPath(),wxT("wb"));
   WriteXMLHeader(writer);
   WriteXML(writer);
   delete mPresets;
}
示例#4
0
void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event))
{
   wxString file = wxT("Audacity-keys.xml");
   wxString path = gPrefs->Read(wxT("/DefaultExportPath"),
                                ::wxGetCwd());

   file = FileSelector(_("Export Keyboard Shortcuts As:"),
                       path,
                       file,
                       wxT("xml"),
                       _("XML files (*.xml)|*.xml|All files|*"),
                       wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
                       this);

   if (!file) {
      return;
   }

   path = wxPathOnly(file);
   gPrefs->Write(wxT("/DefaultExportPath"), path);
   gPrefs->Flush();

   XMLFileWriter prefFile;

   try
   {
      prefFile.Open(file, wxT("wb"));
      mManager->WriteXML(prefFile);
      prefFile.Close();
   }
   catch (const XMLFileWriterException &)
   {
      wxMessageBox(_("Couldn't write to file: ") + file,
                   _("Error Exporting Keyboard Shortcuts"),
                   wxOK | wxCENTRE, this);
   }
}
示例#5
0
void TagsEditor::OnSave(wxCommandEvent & event)
{
   wxString fn;

   // Refresh tags
   TransferDataFromWindow();

   // Ask the user for the real name
   fn = FileSelector(_("Save Metadata As:"),
                     FileNames::DataDir(),
                     wxT("Tags.xml"),
                     wxT("xml"),
                     wxT("*.xml"),
                     wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
                     this);

   // User canceled...
   if (fn.IsEmpty()) {
      return;
   }

   // Create/Open the file
   XMLFileWriter writer;

   try
   {
      writer.Open(fn, wxT("wb"));

      // Remember title and track in case they're read only
      wxString title = mLocal.GetTag(TAG_TITLE);
      wxString track = mLocal.GetTag(TAG_TRACK);

      // Clear title
      if (!mEditTitle) {
         mLocal.SetTag(TAG_TITLE, wxEmptyString);
      }

      // Clear track
      if (!mEditTrack) {
         mLocal.SetTag(TAG_TRACK, wxEmptyString);
      }

      // Write the metadata
      mLocal.WriteXML(writer);

      // Restore title
      if (!mEditTitle) {
         mLocal.SetTag(TAG_TITLE, title);
      }

      // Restore track
      if (!mEditTrack) {
         mLocal.SetTag(TAG_TRACK, track);
      }

      // Close the file
      writer.Close();
   }
   catch (XMLFileWriterException* pException)
   {
      wxMessageBox(wxString::Format(
         _("Couldn't write to file \"%s\": %s"),
         fn.c_str(), pException->GetMessage().c_str()),
         _("Error Saving Tags File"), wxICON_ERROR, this);

      delete pException;
   }
}
示例#6
0
void VSTEffectDialog::OnSave(wxCommandEvent & evt)
{
   int i = mProgram->GetCurrentSelection();
   wxString fn;

   // Ask the user for the real name
   fn = FileSelector(_("Save VST Program As:"),
                     FileNames::DataDir(),
                     mProgram->GetValue() + wxT(".xml"),
                     wxT("xml"),
                     wxT("*.xml"),
                     wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
                     this);

   // User canceled...
   if (fn.IsEmpty()) {
      return;
   }

   XMLFileWriter xmlFile;

   // Create/Open the file
   xmlFile.Open(fn, wxT("wb"));

   xmlFile.StartTag(wxT("vstprogrampersistence"));
   xmlFile.WriteAttr(wxT("version"), wxT("1"));

   i = mEffect->callDispatcher(effGetVendorVersion, 0, 0, NULL, 0.0);
   xmlFile.StartTag(wxT("effect"));
   xmlFile.WriteAttr(wxT("name"), mEffect->GetEffectIdentifier());
   xmlFile.WriteAttr(wxT("version"), i);

   xmlFile.StartTag(wxT("program"));
   xmlFile.WriteAttr(wxT("name"), mProgram->GetValue());

   long clen = 0;
   if (mAEffect->flags & effFlagsProgramChunks) {
      void *chunk = NULL;

      clen = mEffect->callDispatcher(effGetChunk, 1, 0, &chunk, 0.0);
      if (clen != 0) {
         xmlFile.StartTag(wxT("chunk"));
         xmlFile.WriteSubTree(b64encode(chunk, clen) + wxT('\n'));
         xmlFile.EndTag(wxT("chunk"));
      }
   }

   if (clen == 0) {
      for (i = 0; i < mAEffect->numParams; i++) {
         xmlFile.StartTag(wxT("param"));

         xmlFile.WriteAttr(wxT("index"), i);
         xmlFile.WriteAttr(wxT("name"),
                           mEffect->GetString(effGetParamName, i));
         xmlFile.WriteAttr(wxT("value"),
                           wxString::Format(wxT("%f"),
                           mEffect->callGetParameter(i)));

         xmlFile.EndTag(wxT("param"));
      }
   }

   xmlFile.EndTag(wxT("program"));

   xmlFile.EndTag(wxT("effect"));

   xmlFile.EndTag(wxT("vstprogrampersistence"));

   // Close the file
   xmlFile.Close();
}
示例#7
0
bool ConvertLegacyProjectFile(wxFileName filename)
{
   wxTextFile f;
   XMLFileWriter xmlFile;
   int index = 0;
   wxString backupName;

   do {
      index++;
      fflush(stdout);
      backupName = filename.GetPath() + wxFILE_SEP_PATH + filename.GetName() +
         wxT("_bak") + wxString::Format(wxT("%d"), index) + wxT(".") + filename.GetExt();
   } while(::wxFileExists(backupName));

   // This will move the original file out of the way, but 
   // move it back if we exit from this function early.
   AutoRollbackRenamer renamer(filename.GetFullPath(), backupName);
   if (!renamer.RenameSucceeded())
      return false;

   f.Open(backupName);
   if (!f.IsOpened())
      return false;

   wxString name = filename.GetFullPath();

   try
   {
      xmlFile.Open(name, wxT("wb"));
   }
   catch (XMLFileWriterException* pException)
   {
      delete pException;
      return false;
   }

   renamer.SetNewFile(xmlFile.fp());

   try
   {
      xmlFile.Write(wxT("<?xml version=\"1.0\"?>\n"));

      wxString label;
      wxString value;

      if (f.GetFirstLine() != wxT("AudacityProject"))
         return false;
      if (f.GetNextLine() != wxT("Version"))
         return false;
      if (f.GetNextLine() != wxT("0.95"))
         return false;
      if (f.GetNextLine() != wxT("projName"))
         return false;

      xmlFile.StartTag(wxT("audacityproject"));
      xmlFile.WriteAttr(wxT("projname"), f.GetNextLine());
      xmlFile.WriteAttr(wxT("version"), wxT("1.1.0"));
      xmlFile.WriteAttr(wxT("audacityversion"),AUDACITY_VERSION_STRING);

      label = f.GetNextLine();
      while (label != wxT("BeginTracks")) {
         xmlFile.WriteAttr(label, f.GetNextLine());
         label = f.GetNextLine();
      }

      label = f.GetNextLine();
      while (label != wxT("EndTracks")) {
         bool success = ConvertLegacyTrack(&f, xmlFile);
         if (!success)
            return false;
         label = f.GetNextLine();
      }

      xmlFile.EndTag(wxT("audacityproject"));
      xmlFile.Close();
   }
   catch (XMLFileWriterException* pException)
   {
      // Error writing XML file (e.g. disk full)
      delete pException;
      return false;
   }

   renamer.Finished();

   ::wxMessageBox(wxString::Format(_("Converted a 1.0 project file to the new format.\nThe old file has been saved as '%s'"), backupName.c_str()),
                  _("Opening Audacity Project"));

   return true;
}