Esempio n. 1
0
static void save_options(void)
{
	XFILE *file;
	long n;
	int error = 0, h;

	graf_mouse(HOURGLASS, NULL);

	if ((file = x_fopen(optname, O_DENYRW | O_WRONLY, &error)) != NULL)
	{
		if ((n = x_fwrite(file, &options, sizeof(Options))) == sizeof(Options))
		{
			if (options.cprefs & SAVE_COLORS)
				error = save_colors(file);

			if (error == 0)
				if ((error = dsk_save(file)) == 0)
					if ((error = ft_save(file)) == 0)
						if ((error = icnt_save(file)) == 0)
							if ((error = app_save(file)) == 0)
								if ((error = prg_save(file)) == 0)
									error = wd_save(file);
		}
		else
			error = (int) n;

		if (((h = x_fclose(file)) < 0) && (error == 0))
			error = h;
	}

	graf_mouse(ARROW, NULL);

	if (error != 0)
		hndl_error(MSAVECFG, error);

	wd_set_update(WD_UPD_COPIED, optname, NULL);
	wd_do_update();
}
Esempio n. 2
0
bool CapriceLoadSave::HandleMessage(CMessage* pMessage)
{
  bool bHandled = false;

  if (pMessage)
  {
    switch(pMessage->MessageType())
    {
      case CMessage::CTRL_SINGLELCLICK:
        {
          if (pMessage->Destination() == this)
          {
            if (pMessage->Source() == m_pCancelButton) {
              CloseFrame();
              bHandled = true;
              break;
            }
            if (pMessage->Source() == m_pLoadSaveButton) {
              bool actionDone = false;
              std::string filename = m_pFileNameValue->GetWindowText();
              if(!filename.empty()) {
                std::string directory = m_pDirectoryValue->GetWindowText();
                filename = directory + '/' + filename;
                switch (m_pActionValue->GetSelectedIndex()) {
                  case 0: // Load
                    {
                      DRIVE drive;
                      switch (m_pTypeValue->GetSelectedIndex()) {
                        case 0: // Drive A
                          drive = DSK_A;
                          actionDone = true;
                          CPC.current_dsk_path = directory;
                          break;
                        case 1: // Drive B
                          drive = DSK_B;
                          actionDone = true;
                          CPC.current_dsk_path = directory;
                          break;
                        case 2: // Snapshot
                          drive = OTHER;
                          actionDone = true;
                          CPC.current_snap_path = directory;
                          break;
                        case 3: // Tape
                          drive = OTHER;
                          actionDone = true;
                          CPC.current_tape_path = directory;
                          break;
                        case 4: // Cartridge
                          drive = OTHER;
                          actionDone = true;
                          CPC.current_cart_path = directory;
                          break;
                      }
                      if (actionDone) {
                        file_load(filename, drive);
                      }
                      if (m_pTypeValue->GetSelectedIndex() == 4) {
                        emulator_reset(false);
                      }
                      break;
                    }
                  case 1: // Save
                    // TODO(cpitrat): Ensure the proper extension is present in the filename, otherwise add it.
                    switch (m_pTypeValue->GetSelectedIndex()) {
                      case 0: // Drive A
                        std::cout << "Save dsk A: " << filename << std::endl;
                        dsk_save(filename, &driveA);
                        actionDone = true;
                        break;
                      case 1: // Drive B
                        std::cout << "Save dsk B: " << filename << std::endl;
                        dsk_save(filename, &driveB);
                        actionDone = true;
                        break;
                      case 2: // Snapshot
                        std::cout << "Save snapshot: " << filename << std::endl;
                        snapshot_save(filename);
                        actionDone = true;
                        break;
                      case 3: // Tape
                        {
                          std::cout << "Save tape: " << filename << std::endl;
                          // Unsupported
                          wGui::CMessageBox *pMessageBox = new wGui::CMessageBox(CRect(CPoint(m_ClientRect.Width() /2 - 125, m_ClientRect.Height() /2 - 30), 250, 60), this, nullptr, "Not implemented", "Saving tape not yet implemented", CMessageBox::BUTTON_OK);
                          pMessageBox->SetModal(true);
                          //tape_save(filename);
                          break;
                        }
                      case 4: // Cartridge
                        {
                          std::cout << "Save cartridge: " << filename << std::endl;
                          // Unsupported
                          wGui::CMessageBox *pMessageBox = new wGui::CMessageBox(CRect(CPoint(m_ClientRect.Width() /2 - 125, m_ClientRect.Height() /2 - 30), 250, 60), this, nullptr, "Not implemented", "Saving cartridge not yet implemented", CMessageBox::BUTTON_OK);
                          pMessageBox->SetModal(true);
                          //cpr_save(filename);
                          break;
                        }
                    }
                    break;
                }
              }
              if(actionDone) {
                CloseFrame();
              }
              bHandled = true;
              break;
            }
          }
        }
        break;

      case CMessage::CTRL_VALUECHANGE:
        if (pMessage->Destination() == m_pActionValue) {
          switch (m_pActionValue->GetSelectedIndex()) {
            case 0: // Load
              m_pLoadSaveButton->SetWindowText("Load");
              m_pFileNameValue->SetReadOnly(true);
              break;
            case 1: // Save
              m_pLoadSaveButton->SetWindowText("Save");
              m_pFileNameValue->SetReadOnly(false);
              break;
          }
        }
        if (pMessage->Destination() == m_pTypeValue) {
          switch (m_pTypeValue->GetSelectedIndex()) {
            case 0: // Drive A
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_dsk_path));
#ifndef WITH_IPF
              m_fileSpec = { ".dsk", ".zip" };
#else
              m_fileSpec = { ".dsk", ".ipf", ".zip" };
#endif
              UpdateFilesList();
              break;
            case 1: // Drive B
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_dsk_path));
              m_fileSpec = { ".dsk", ".zip" };
              UpdateFilesList();
              break;
            case 2: // Snapshot
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_snap_path));
              m_fileSpec = { ".sna", ".zip" };
              UpdateFilesList();
              break;
            case 3: // Tape
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_tape_path));
              m_fileSpec = { ".cdt", ".voc", ".zip" };
              UpdateFilesList();
              break;
            case 4: // Cartridge
              m_pDirectoryValue->SetWindowText(simplifyDirPath(CPC.current_cart_path));
              m_fileSpec = { ".cpr", ".zip" };
              UpdateFilesList();
              break;
          }
        }
        if (pMessage->Source() == m_pFilesList) {
          int idx = m_pFilesList->getFirstSelectedIndex();
          std::string fn;
          if (idx != -1) {
            fn = m_pFilesList->GetItem(idx).sItemText;
          }
          if(!fn.empty() && fn[fn.size()-1] == '/') {
            m_pDirectoryValue->SetWindowText(simplifyDirPath(m_pDirectoryValue->GetWindowText() + '/' + fn));
            m_pFileNameValue->SetWindowText("");
            UpdateFilesList();
          } else {
            m_pFileNameValue->SetWindowText(fn);
          }
        }
        break;

      default :
        break;
    }
  }
  if (!bHandled) {
    bHandled = CFrame::HandleMessage(pMessage);
  }
  return bHandled;
}