GUI: add option to toggle save compression
This commit is contained in:
parent
dae87a4980
commit
347d35be19
|
@ -1968,8 +1968,6 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
|||
//ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_NavEnableKeyboard;
|
||||
}
|
||||
|
||||
#define FURNACE_ZLIB_COMPRESS
|
||||
|
||||
int FurnaceGUI::save(String path, int dmfVersion) {
|
||||
SafeWriter* w;
|
||||
logD("saving file...");
|
||||
|
@ -1992,35 +1990,56 @@ int FurnaceGUI::save(String path, int dmfVersion) {
|
|||
w->finish();
|
||||
return 1;
|
||||
}
|
||||
#ifdef FURNACE_ZLIB_COMPRESS
|
||||
unsigned char zbuf[131072];
|
||||
int ret;
|
||||
z_stream zl;
|
||||
memset(&zl,0,sizeof(z_stream));
|
||||
ret=deflateInit(&zl,Z_DEFAULT_COMPRESSION);
|
||||
if (ret!=Z_OK) {
|
||||
logE("zlib error!");
|
||||
lastError="compression error";
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 2;
|
||||
}
|
||||
zl.avail_in=w->size();
|
||||
zl.next_in=w->getFinalBuf();
|
||||
while (zl.avail_in>0) {
|
||||
if (settings.compress) {
|
||||
unsigned char zbuf[131072];
|
||||
int ret;
|
||||
z_stream zl;
|
||||
memset(&zl,0,sizeof(z_stream));
|
||||
ret=deflateInit(&zl,Z_DEFAULT_COMPRESSION);
|
||||
if (ret!=Z_OK) {
|
||||
logE("zlib error!");
|
||||
lastError="compression error";
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 2;
|
||||
}
|
||||
zl.avail_in=w->size();
|
||||
zl.next_in=w->getFinalBuf();
|
||||
while (zl.avail_in>0) {
|
||||
zl.avail_out=131072;
|
||||
zl.next_out=zbuf;
|
||||
if ((ret=deflate(&zl,Z_NO_FLUSH))==Z_STREAM_ERROR) {
|
||||
logE("zlib stream error!");
|
||||
lastError="zlib stream error";
|
||||
deflateEnd(&zl);
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 2;
|
||||
}
|
||||
size_t amount=131072-zl.avail_out;
|
||||
if (amount>0) {
|
||||
if (fwrite(zbuf,1,amount,outFile)!=amount) {
|
||||
logE("did not write entirely: %s!",strerror(errno));
|
||||
lastError=strerror(errno);
|
||||
deflateEnd(&zl);
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
zl.avail_out=131072;
|
||||
zl.next_out=zbuf;
|
||||
if ((ret=deflate(&zl,Z_NO_FLUSH))==Z_STREAM_ERROR) {
|
||||
logE("zlib stream error!");
|
||||
lastError="zlib stream error";
|
||||
if ((ret=deflate(&zl,Z_FINISH))==Z_STREAM_ERROR) {
|
||||
logE("zlib finish stream error!");
|
||||
lastError="zlib finish stream error";
|
||||
deflateEnd(&zl);
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 2;
|
||||
}
|
||||
size_t amount=131072-zl.avail_out;
|
||||
if (amount>0) {
|
||||
if (fwrite(zbuf,1,amount,outFile)!=amount) {
|
||||
if (131072-zl.avail_out>0) {
|
||||
if (fwrite(zbuf,1,131072-zl.avail_out,outFile)!=(131072-zl.avail_out)) {
|
||||
logE("did not write entirely: %s!",strerror(errno));
|
||||
lastError=strerror(errno);
|
||||
deflateEnd(&zl);
|
||||
|
@ -2029,37 +2048,16 @@ int FurnaceGUI::save(String path, int dmfVersion) {
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
zl.avail_out=131072;
|
||||
zl.next_out=zbuf;
|
||||
if ((ret=deflate(&zl,Z_FINISH))==Z_STREAM_ERROR) {
|
||||
logE("zlib finish stream error!");
|
||||
lastError="zlib finish stream error";
|
||||
deflateEnd(&zl);
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 2;
|
||||
}
|
||||
if (131072-zl.avail_out>0) {
|
||||
if (fwrite(zbuf,1,131072-zl.avail_out,outFile)!=(131072-zl.avail_out)) {
|
||||
} else {
|
||||
if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) {
|
||||
logE("did not write entirely: %s!",strerror(errno));
|
||||
lastError=strerror(errno);
|
||||
deflateEnd(&zl);
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
deflateEnd(&zl);
|
||||
#else
|
||||
if (fwrite(w->getFinalBuf(),1,w->size(),outFile)!=w->size()) {
|
||||
logE("did not write entirely: %s!",strerror(errno));
|
||||
lastError=strerror(errno);
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
fclose(outFile);
|
||||
w->finish();
|
||||
backupLock.lock();
|
||||
|
|
|
@ -1424,6 +1424,7 @@ class FurnaceGUI {
|
|||
int alwaysPlayIntro;
|
||||
int iCannotWait;
|
||||
int orderButtonPos;
|
||||
int compress;
|
||||
unsigned int maxUndoSteps;
|
||||
String mainFontPath;
|
||||
String patFontPath;
|
||||
|
@ -1569,6 +1570,7 @@ class FurnaceGUI {
|
|||
alwaysPlayIntro(0),
|
||||
iCannotWait(0),
|
||||
orderButtonPos(2),
|
||||
compress(1),
|
||||
maxUndoSteps(100),
|
||||
mainFontPath(""),
|
||||
patFontPath(""),
|
||||
|
|
|
@ -654,6 +654,15 @@ void FurnaceGUI::drawSettings() {
|
|||
settings.saveUnusedPatterns=saveUnusedPatternsB;
|
||||
}
|
||||
|
||||
bool compressB=settings.compress;
|
||||
if (ImGui::Checkbox("Compress when saving",&compressB)) {
|
||||
settings.compress=compressB;
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("use zlib to compress saved songs.");
|
||||
}
|
||||
|
||||
|
||||
bool cursorFollowsOrderB=settings.cursorFollowsOrder;
|
||||
if (ImGui::Checkbox("Cursor follows current order when moving it",&cursorFollowsOrderB)) {
|
||||
settings.cursorFollowsOrder=cursorFollowsOrderB;
|
||||
|
@ -2673,6 +2682,7 @@ void FurnaceGUI::syncSettings() {
|
|||
settings.cursorFollowsOrder=e->getConfInt("cursorFollowsOrder",1);
|
||||
settings.iCannotWait=e->getConfInt("iCannotWait",0);
|
||||
settings.orderButtonPos=e->getConfInt("orderButtonPos",2);
|
||||
settings.compress=e->getConfInt("compress",1);
|
||||
|
||||
clampSetting(settings.mainFontSize,2,96);
|
||||
clampSetting(settings.patFontSize,2,96);
|
||||
|
@ -2793,6 +2803,7 @@ void FurnaceGUI::syncSettings() {
|
|||
clampSetting(settings.cursorFollowsOrder,0,1);
|
||||
clampSetting(settings.iCannotWait,0,1);
|
||||
clampSetting(settings.orderButtonPos,0,2);
|
||||
clampSetting(settings.compress,0,1);
|
||||
|
||||
if (settings.exportLoops<0.0) settings.exportLoops=0.0;
|
||||
if (settings.exportFadeOut<0.0) settings.exportFadeOut=0.0;
|
||||
|
@ -3008,6 +3019,7 @@ void FurnaceGUI::commitSettings() {
|
|||
e->setConf("cursorFollowsOrder",settings.cursorFollowsOrder);
|
||||
e->setConf("iCannotWait",settings.iCannotWait);
|
||||
e->setConf("orderButtonPos",settings.orderButtonPos);
|
||||
e->setConf("compress",settings.compress);
|
||||
|
||||
// colors
|
||||
for (int i=0; i<GUI_COLOR_MAX; i++) {
|
||||
|
|
Loading…
Reference in New Issue