mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-04 20:05:05 +00:00
add backup functionality - UNTESTED
This commit is contained in:
parent
b45d2be312
commit
8c961f0aae
4 changed files with 62 additions and 4 deletions
|
@ -278,7 +278,8 @@ class DivEngine {
|
||||||
// save as .dmf.
|
// save as .dmf.
|
||||||
SafeWriter* saveDMF(unsigned char version);
|
SafeWriter* saveDMF(unsigned char version);
|
||||||
// save as .fur.
|
// save as .fur.
|
||||||
SafeWriter* saveFur();
|
// if notPrimary is true then the song will not be altered
|
||||||
|
SafeWriter* saveFur(bool notPrimary=false);
|
||||||
// build a ROM file (TODO).
|
// build a ROM file (TODO).
|
||||||
// specify system to build ROM for.
|
// specify system to build ROM for.
|
||||||
SafeWriter* buildROM(int sys);
|
SafeWriter* buildROM(int sys);
|
||||||
|
|
|
@ -1728,7 +1728,7 @@ bool DivEngine::load(unsigned char* f, size_t slen) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeWriter* DivEngine::saveFur() {
|
SafeWriter* DivEngine::saveFur(bool notPrimary) {
|
||||||
int insPtr[256];
|
int insPtr[256];
|
||||||
int wavePtr[256];
|
int wavePtr[256];
|
||||||
int samplePtr[256];
|
int samplePtr[256];
|
||||||
|
@ -1736,8 +1736,10 @@ SafeWriter* DivEngine::saveFur() {
|
||||||
size_t ptrSeek;
|
size_t ptrSeek;
|
||||||
warnings="";
|
warnings="";
|
||||||
|
|
||||||
|
if (!notPrimary) {
|
||||||
song.isDMF=false;
|
song.isDMF=false;
|
||||||
song.version=DIV_ENGINE_VERSION;
|
song.version=DIV_ENGINE_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
SafeWriter* w=new SafeWriter;
|
SafeWriter* w=new SafeWriter;
|
||||||
w->init();
|
w->init();
|
||||||
|
|
|
@ -52,11 +52,13 @@ extern "C" {
|
||||||
#include <shlwapi.h>
|
#include <shlwapi.h>
|
||||||
#include "../utfutils.h"
|
#include "../utfutils.h"
|
||||||
#define LAYOUT_INI "\\layout.ini"
|
#define LAYOUT_INI "\\layout.ini"
|
||||||
|
#define BACKUP_FUR "\\backup.fur"
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#define LAYOUT_INI "/layout.ini"
|
#define LAYOUT_INI "/layout.ini"
|
||||||
|
#define BACKUP_FUR "/backup.fur"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Particle::update(float frameTime) {
|
bool Particle::update(float frameTime) {
|
||||||
|
@ -4802,11 +4804,13 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
||||||
|
|
||||||
int FurnaceGUI::save(String path, int dmfVersion) {
|
int FurnaceGUI::save(String path, int dmfVersion) {
|
||||||
SafeWriter* w;
|
SafeWriter* w;
|
||||||
|
backupLock.lock();
|
||||||
if (dmfVersion) {
|
if (dmfVersion) {
|
||||||
w=e->saveDMF(dmfVersion);
|
w=e->saveDMF(dmfVersion);
|
||||||
} else {
|
} else {
|
||||||
w=e->saveFur();
|
w=e->saveFur();
|
||||||
}
|
}
|
||||||
|
backupLock.unlock();
|
||||||
if (w==NULL) {
|
if (w==NULL) {
|
||||||
lastError=e->getLastError();
|
lastError=e->getLastError();
|
||||||
return 3;
|
return 3;
|
||||||
|
@ -6411,6 +6415,41 @@ bool FurnaceGUI::loop() {
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// backup trigger
|
||||||
|
if (modified) {
|
||||||
|
if (backupTimer>0) {
|
||||||
|
backupTimer-=ImGui::GetIO().DeltaTime;
|
||||||
|
if (backupTimer<=0) {
|
||||||
|
backupTask=std::async(std::launch::async,[this]() -> bool {
|
||||||
|
if (backupPath==curFileName) {
|
||||||
|
logD("backup file open. not saving backup.\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
logD("saving backup...\n");
|
||||||
|
backupLock.lock();
|
||||||
|
SafeWriter* w=e->saveFur(true);
|
||||||
|
backupLock.unlock();
|
||||||
|
|
||||||
|
if (w!=NULL) {
|
||||||
|
FILE* outFile=ps_fopen(backupPath.c_str(),"wb");
|
||||||
|
if (outFile!=NULL) {
|
||||||
|
if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) {
|
||||||
|
logW("did not write backup entirely: %s!\n",strerror(errno));
|
||||||
|
fclose(outFile);
|
||||||
|
w->finish();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logW("could not save backup: %s!\n",strerror(errno));
|
||||||
|
w->finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
backupTimer=30.0;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SDL_SetRenderDrawColor(sdlRend,uiColors[GUI_COLOR_BACKGROUND].x*255,
|
SDL_SetRenderDrawColor(sdlRend,uiColors[GUI_COLOR_BACKGROUND].x*255,
|
||||||
uiColors[GUI_COLOR_BACKGROUND].y*255,
|
uiColors[GUI_COLOR_BACKGROUND].y*255,
|
||||||
uiColors[GUI_COLOR_BACKGROUND].z*255,
|
uiColors[GUI_COLOR_BACKGROUND].z*255,
|
||||||
|
@ -6930,6 +6969,7 @@ bool FurnaceGUI::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(finalLayoutPath,(e->getConfigPath()+String(LAYOUT_INI)).c_str(),4095);
|
strncpy(finalLayoutPath,(e->getConfigPath()+String(LAYOUT_INI)).c_str(),4095);
|
||||||
|
backupPath=e->getConfigPath()+String(BACKUP_FUR);
|
||||||
prepareLayout();
|
prepareLayout();
|
||||||
|
|
||||||
ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_DockingEnable;
|
ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_DockingEnable;
|
||||||
|
@ -6969,6 +7009,7 @@ bool FurnaceGUI::init() {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
SDL_RaiseWindow(sdlWin);
|
SDL_RaiseWindow(sdlWin);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7020,6 +7061,11 @@ bool FurnaceGUI::finish() {
|
||||||
for (int i=0; i<DIV_MAX_CHANS; i++) {
|
for (int i=0; i<DIV_MAX_CHANS; i++) {
|
||||||
delete oldPat[i];
|
delete oldPat[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (backupTask.valid()) {
|
||||||
|
backupTask.get();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7047,6 +7093,7 @@ FurnaceGUI::FurnaceGUI():
|
||||||
aboutScroll(0),
|
aboutScroll(0),
|
||||||
aboutSin(0),
|
aboutSin(0),
|
||||||
aboutHue(0.0f),
|
aboutHue(0.0f),
|
||||||
|
backupTimer(0.1),
|
||||||
curIns(0),
|
curIns(0),
|
||||||
curWave(0),
|
curWave(0),
|
||||||
curSample(0),
|
curSample(0),
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <future>
|
||||||
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "fileDialog.h"
|
#include "fileDialog.h"
|
||||||
|
@ -512,6 +514,11 @@ class FurnaceGUI {
|
||||||
double aboutScroll, aboutSin;
|
double aboutScroll, aboutSin;
|
||||||
float aboutHue;
|
float aboutHue;
|
||||||
|
|
||||||
|
double backupTimer;
|
||||||
|
std::future<bool> backupTask;
|
||||||
|
std::mutex backupLock;
|
||||||
|
String backupPath;
|
||||||
|
|
||||||
ImFont* mainFont;
|
ImFont* mainFont;
|
||||||
ImFont* iconFont;
|
ImFont* iconFont;
|
||||||
ImFont* patFont;
|
ImFont* patFont;
|
||||||
|
@ -875,6 +882,7 @@ class FurnaceGUI {
|
||||||
void updateScroll(int amount);
|
void updateScroll(int amount);
|
||||||
void addScroll(int amount);
|
void addScroll(int amount);
|
||||||
void setFileName(String name);
|
void setFileName(String name);
|
||||||
|
void runBackupThread();
|
||||||
bool loop();
|
bool loop();
|
||||||
bool finish();
|
bool finish();
|
||||||
bool init();
|
bool init();
|
||||||
|
|
Loading…
Reference in a new issue