Пример #1
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();
}
Пример #2
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();

   xmlFile.Open(name, wxT("wb"));
   if (!xmlFile.IsOpened())
      return false;

   renamer.SetNewFile(xmlFile.fp());

   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"), wxT(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"));

   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;
}