/* EntryOperations::exportAsPNG * Converts [entry] to a PNG image (if possible) and saves the PNG * data to a file [filename]. Does not alter the entry data itself *******************************************************************/ bool EntryOperations::exportAsPNG(ArchiveEntry* entry, string filename) { // Check entry was given if (!entry) return false; // Create image from entry SImage image; if (!Misc::loadImageFromEntry(&image, entry)) { wxLogMessage("Error converting %s: %s", entry->getName(), Global::error); return false; } // Write png data MemChunk png; SIFormat* fmt_png = SIFormat::getFormat("png"); if (!fmt_png->saveImage(image, png, theMainWindow->getPaletteChooser()->getSelectedPalette(entry))) { wxLogMessage("Error converting %s", entry->getName()); return false; } // Export file return png.exportFile(filename); }
/* ADatArchive::write * Writes the dat archive to a file * Returns true if successful, false otherwise *******************************************************************/ bool ADatArchive::write(string filename, bool update) { // Write to a MemChunk, then export it to a file MemChunk mc; if (write(mc, true)) return mc.exportFile(filename); else return false; }
// ----------------------------------------------------------------------------- // Application exit, shuts down and cleans everything up. // If [save_config] is true, saves all configuration related files // ----------------------------------------------------------------------------- void App::exit(bool save_config) { exiting = true; if (save_config) { // Save configuration saveConfigFile(); // Save text style configuration StyleSet::saveCurrent(); // Save colour configuration MemChunk ccfg; ColourConfiguration::writeConfiguration(ccfg); ccfg.exportFile(App::path("colours.cfg", App::Dir::User)); // Save game exes wxFile f; f.Open(App::path("executables.cfg", App::Dir::User), wxFile::write); f.Write(Executables::writeExecutables()); f.Close(); // Save custom special presets Game::saveCustomSpecialPresets(); // Save custom scripts ScriptManager::saveUserScripts(); } // Close all open archives archive_manager.closeAll(); // Clean up EntryType::cleanupEntryTypes(); Drawing::cleanupFonts(); OpenGL::Texture::clearAll(); // Clear temp folder std::error_code error; for (auto& item : std::filesystem::directory_iterator{ App::path("", App::Dir::Temp) }) { if (!item.is_regular_file()) continue; if (!std::filesystem::remove(item, error)) Log::warning("Could not clean up temporary file \"{}\": {}", item.path().string(), error.message()); } // Close lua Lua::close(); // Close DUMB dumb_exit(); // Exit wx Application wxGetApp().Exit(); }
bool exportEntry() { wxFileName fn(appPath(entry->getName(), DIR_TEMP)); fn.SetExt("mid"); // Convert to WAV data MemChunk convdata; // Doom Sound if (entry->getType()->getFormat() == "snd_doom" || entry->getType()->getFormat() == "snd_doom_mac") Conversions::doomSndToWav(entry->getMCData(), convdata); // Doom PC Speaker Sound else if (entry->getType()->getFormat() == "snd_speaker") Conversions::spkSndToWav(entry->getMCData(), convdata); // AudioT PC Speaker Sound else if (entry->getType()->getFormat() == "snd_audiot") Conversions::spkSndToWav(entry->getMCData(), convdata, true); // Wolfenstein 3D Sound else if (entry->getType()->getFormat() == "snd_wolf") Conversions::wolfSndToWav(entry->getMCData(), convdata); // Creative Voice File else if (entry->getType()->getFormat() == "snd_voc") Conversions::vocToWav(entry->getMCData(), convdata); // Jaguar Doom Sound else if (entry->getType()->getFormat() == "snd_jaguar") Conversions::jagSndToWav(entry->getMCData(), convdata); // Blood Sound else if (entry->getType()->getFormat() == "snd_bloodsfx") Conversions::bloodToWav(entry, convdata); else { Global::error = S_FMT("Type %s can not be converted to WAV", CHR(entry->getType()->getName())); return false; } // Export file and start monitoring if successful filename = fn.GetFullPath(); if (convdata.exportFile(filename)) { file_modified = wxFileModificationTime(filename); Start(1000); return true; } return false; }
/* ZipArchive::open * Reads zip format data from a MemChunk * Returns true if successful, false otherwise *******************************************************************/ bool ZipArchive::open(MemChunk& mc) { // Write the MemChunk to a temp file string tempfile = appPath("slade-temp-open.zip", DIR_TEMP); mc.exportFile(tempfile); // Load the file bool success = open(tempfile); // Clean up wxRemoveFile(tempfile); return success; }
/* MainApp::OnExit * Application shutdown, run when program is closed *******************************************************************/ int MainApp::OnExit() { exiting = true; // Save configuration saveConfigFile(); // Save text style configuration StyleSet::saveCurrent(); // Save colour configuration MemChunk ccfg; ColourConfiguration::writeConfiguration(ccfg); ccfg.exportFile(appPath("colours.cfg", DIR_USER)); // Save game exes wxFile f; f.Open(appPath("executables.cfg", DIR_USER), wxFile::write); f.Write(Executables::writeExecutables()); f.Close(); // Close the map editor if it's open MapEditorWindow::deleteInstance(); // Close all open archives theArchiveManager->closeAll(); // Clean up EntryType::cleanupEntryTypes(); ArchiveManager::deleteInstance(); Console::deleteInstance(); SplashWindow::deleteInstance(); // Clear temp folder wxDir temp; temp.Open(appPath("", DIR_TEMP)); string filename = wxEmptyString; bool files = temp.GetFirst(&filename, wxEmptyString, wxDIR_FILES); while (files) { if (!wxRemoveFile(appPath(filename, DIR_TEMP))) wxLogMessage("Warning: Could not clean up temporary file \"%s\"", filename); files = temp.GetNext(&filename); } // Close lua Lua::close(); return 0; }
bool exportEntry() { wxFileName fn(appPath(entry->getName(), DIR_TEMP)); fn.SetExt("png"); // Create image from entry SImage image; if (!Misc::loadImageFromEntry(&image, entry)) { Global::error = "Could not read graphic"; return false; } // Set export info gfx_format = image.getFormat()->getId(); offsets = image.offset(); palette.copyPalette(theMainWindow->getPaletteChooser()->getSelectedPalette(entry)); // Write png data MemChunk png; SIFormat* fmt_png = SIFormat::getFormat("png"); if (!fmt_png->saveImage(image, png, &palette)) { Global::error = "Error converting to png"; return false; } // Export file and start monitoring if successful filename = fn.GetFullPath(); if (png.exportFile(filename)) { file_modified = wxFileModificationTime(filename); Start(1000); return true; } return false; }
bool exportEntry() { wxFileName fn(appPath(entry->getName(), DIR_TEMP)); fn.SetExt("mid"); // Convert to MIDI data MemChunk convdata; // MUS if (entry->getType()->getFormat() == "midi_mus") Conversions::musToMidi(entry->getMCData(), convdata); // HMI/HMP/XMI else if (entry->getType()->getFormat() == "midi_xmi" || entry->getType()->getFormat() == "midi_hmi" || entry->getType()->getFormat() == "midi_hmp") Conversions::zmusToMidi(entry->getMCData(), convdata, 0); // GMID else if (entry->getType()->getFormat() == "midi_gmid") Conversions::gmidToMidi(entry->getMCData(), convdata); else { Global::error = S_FMT("Type %s can not be converted to MIDI", CHR(entry->getType()->getName())); return false; } // Export file and start monitoring if successful filename = fn.GetFullPath(); if (convdata.exportFile(filename)) { file_modified = wxFileModificationTime(filename); Start(1000); return true; } return false; }
/* AudioEntryPanel::openAudio * Opens an audio file for playback (SFML 2.x+) *******************************************************************/ bool AudioEntryPanel::openAudio(MemChunk& audio, string filename) { // Stop if sound currently playing resetStream(); // (Re)create sound buffer if (sound_buffer) delete sound_buffer; sound_buffer = new sf::SoundBuffer(); audio_type = AUTYPE_INVALID; // Load into buffer if (sound_buffer->loadFromMemory((const char*)audio.getData(), audio.getSize())) { LOG_MESSAGE(3, "opened as sound"); // Bind to sound sound->setBuffer(*sound_buffer); audio_type = AUTYPE_SOUND; // Enable play controls #if (SFML_VERSION_MAJOR == 2 && SFML_VERSION_MINOR < 2) // SFML before 2.2 has a bug where it reports an incorrect value for long sounds, so compute it ourselves then setAudioDuration((sound_buffer->getSampleCount() / sound_buffer->getSampleRate())*(1000/sound_buffer->getChannelCount())); #else setAudioDuration(sound_buffer->getDuration().asMilliseconds()); #endif btn_play->Enable(); btn_pause->Enable(); btn_stop->Enable(); return true; } else if (music->openFromMemory((const char*)audio.getData(), audio.getSize())) { LOG_MESSAGE(3, "opened as music"); // Couldn't open the audio as a sf::SoundBuffer, try sf::Music instead audio_type = AUTYPE_MUSIC; // Enable play controls setAudioDuration(music->getDuration().asMilliseconds()); btn_play->Enable(); btn_stop->Enable(); return true; } else { // Couldn't open as sound or music, try the wxMediaCtrl LOG_MESSAGE(3, "opened as media"); // Dump audio to temp file audio.exportFile(filename); if (openMedia(filename)) return true; } // Unable to open audio, disable play controls setAudioDuration(0); btn_play->Enable(false); btn_pause->Enable(false); btn_stop->Enable(false); return false; }