Added a progress dialog for saving Qt TAS projects to disk.
This commit is contained in:
parent
a28bbb3ce3
commit
72af0270a3
|
@ -393,11 +393,19 @@ void BOOKMARKS::save(EMUFILE *os, bool really_save)
|
|||
{
|
||||
if (really_save)
|
||||
{
|
||||
setTasProjectProgressBarText("Saving Bookmarks...");
|
||||
setTasProjectProgressBar( 0, TOTAL_BOOKMARKS );
|
||||
|
||||
// write "BOOKMARKS" string
|
||||
os->fwrite(bookmarks_save_id, BOOKMARKS_ID_LEN);
|
||||
// write all 10 bookmarks
|
||||
for (int i = 0; i < TOTAL_BOOKMARKS; ++i)
|
||||
{
|
||||
setTasProjectProgressBar( i, TOTAL_BOOKMARKS );
|
||||
bookmarksArray[i].save(os);
|
||||
}
|
||||
setTasProjectProgressBar( TOTAL_BOOKMARKS, TOTAL_BOOKMARKS );
|
||||
|
||||
// write branches
|
||||
branches->save(os);
|
||||
} else
|
||||
|
|
|
@ -440,6 +440,9 @@ void BRANCHES::update()
|
|||
|
||||
void BRANCHES::save(EMUFILE *os)
|
||||
{
|
||||
setTasProjectProgressBarText("Saving Branches...");
|
||||
setTasProjectProgressBar( 0, TOTAL_BOOKMARKS );
|
||||
|
||||
// write cloud time
|
||||
os->fwrite(cloudTimestamp, TIMESTAMP_LENGTH);
|
||||
// write current branch and flag of changes since it
|
||||
|
@ -469,6 +472,7 @@ void BRANCHES::save(EMUFILE *os)
|
|||
write32le(cachedFirstDifferences[i][t], os);
|
||||
}
|
||||
}
|
||||
setTasProjectProgressBar( TOTAL_BOOKMARKS, TOTAL_BOOKMARKS );
|
||||
}
|
||||
// returns true if couldn't load
|
||||
bool BRANCHES::load(EMUFILE *is)
|
||||
|
|
|
@ -236,6 +236,7 @@ void GREENZONE::save(EMUFILE *os, int save_type)
|
|||
{
|
||||
if (save_type != GREENZONE_SAVING_MODE_NO)
|
||||
{
|
||||
setTasProjectProgressBarText("Saving Greenzone...");
|
||||
collectCurrentState(); // in case the project is being saved before the greenzone.update() was called within current frame
|
||||
runGreenzoneCleaning();
|
||||
if (greenzoneSize > (int)savestates.size())
|
||||
|
@ -248,9 +249,11 @@ void GREENZONE::save(EMUFILE *os, int save_type)
|
|||
write32le(greenzoneSize, os);
|
||||
// write Playback cursor position
|
||||
write32le(currFrameCounter, os);
|
||||
|
||||
setTasProjectProgressBar( 0, greenzoneSize );
|
||||
}
|
||||
int frame, size;
|
||||
int last_tick = 0;
|
||||
int last_tick = -1;
|
||||
|
||||
switch (save_type)
|
||||
{
|
||||
|
@ -262,7 +265,8 @@ void GREENZONE::save(EMUFILE *os, int save_type)
|
|||
// update TASEditor progressbar from time to time
|
||||
if (frame / PROGRESSBAR_UPDATE_RATE > last_tick)
|
||||
{
|
||||
playback->setProgressbar(frame, greenzoneSize);
|
||||
setTasProjectProgressBar( frame, greenzoneSize );
|
||||
//playback->setProgressbar(frame, greenzoneSize);
|
||||
last_tick = frame / PROGRESSBAR_UPDATE_RATE;
|
||||
}
|
||||
if (!savestates[frame].size()) continue;
|
||||
|
@ -286,7 +290,8 @@ void GREENZONE::save(EMUFILE *os, int save_type)
|
|||
// update TASEditor progressbar from time to time
|
||||
if (frame / PROGRESSBAR_UPDATE_RATE > last_tick)
|
||||
{
|
||||
playback->setProgressbar(frame, greenzoneSize);
|
||||
setTasProjectProgressBar( frame, greenzoneSize );
|
||||
//playback->setProgressbar(frame, greenzoneSize);
|
||||
last_tick = frame / PROGRESSBAR_UPDATE_RATE;
|
||||
}
|
||||
if (!savestates[frame].size()) continue;
|
||||
|
@ -311,7 +316,8 @@ void GREENZONE::save(EMUFILE *os, int save_type)
|
|||
// update TASEditor progressbar from time to time
|
||||
if (frame / PROGRESSBAR_UPDATE_RATE > last_tick)
|
||||
{
|
||||
playback->setProgressbar(frame, greenzoneSize);
|
||||
setTasProjectProgressBar( frame, greenzoneSize );
|
||||
//playback->setProgressbar(frame, greenzoneSize);
|
||||
last_tick = frame / PROGRESSBAR_UPDATE_RATE;
|
||||
}
|
||||
if (!savestates[frame].size()) continue;
|
||||
|
@ -345,6 +351,10 @@ void GREENZONE::save(EMUFILE *os, int save_type)
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (save_type != GREENZONE_SAVING_MODE_NO)
|
||||
{
|
||||
setTasProjectProgressBar( greenzoneSize, greenzoneSize );
|
||||
}
|
||||
}
|
||||
// returns true if couldn't load
|
||||
bool GREENZONE::load(EMUFILE *is, unsigned int offset)
|
||||
|
@ -357,7 +367,8 @@ bool GREENZONE::load(EMUFILE *is, unsigned int offset)
|
|||
if (offset)
|
||||
{
|
||||
if (is->fseek(offset, SEEK_SET)) goto error;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
reset();
|
||||
playback->restartPlaybackFromZeroGround(); // reset Playback cursor to frame 0
|
||||
|
|
|
@ -989,7 +989,11 @@ void HISTORY::save(EMUFILE *os, bool really_save)
|
|||
{
|
||||
if (really_save)
|
||||
{
|
||||
int real_pos, last_tick = 0;
|
||||
int real_pos, last_tick = -1;
|
||||
|
||||
setTasProjectProgressBarText("Saving History...");
|
||||
setTasProjectProgressBar( 0, historyTotalItems );
|
||||
|
||||
// write "HISTORY" string
|
||||
os->fwrite(historySaveID, HISTORY_ID_LEN);
|
||||
// write vars
|
||||
|
@ -1004,11 +1008,14 @@ void HISTORY::save(EMUFILE *os, bool really_save)
|
|||
os->fwrite(¤tBranchNumberBackups[real_pos], 1);
|
||||
if (i / SAVING_HISTORY_PROGRESSBAR_UPDATE_RATE > last_tick)
|
||||
{
|
||||
playback->setProgressbar(i, historyTotalItems);
|
||||
setTasProjectProgressBar( i, historyTotalItems );
|
||||
//playback->setProgressbar(i, historyTotalItems);
|
||||
last_tick = i / PROGRESSBAR_UPDATE_RATE;
|
||||
}
|
||||
}
|
||||
} else
|
||||
setTasProjectProgressBar( historyTotalItems, historyTotalItems );
|
||||
}
|
||||
else
|
||||
{
|
||||
// write "HISTORX" string
|
||||
os->fwrite(historySkipSaveID, HISTORY_ID_LEN);
|
||||
|
|
|
@ -64,11 +64,16 @@ void MARKERS_MANAGER::save(EMUFILE *os, bool really_save)
|
|||
{
|
||||
if (really_save)
|
||||
{
|
||||
setTasProjectProgressBarText("Saving Markers...");
|
||||
setTasProjectProgressBar( 0, 100 );
|
||||
|
||||
// write "MARKERS" string
|
||||
os->fwrite(markers_save_id, MARKERS_ID_LEN);
|
||||
markers.resetCompressedStatus(); // must recompress data, because most likely it has changed since last compression
|
||||
markers.save(os);
|
||||
} else
|
||||
setTasProjectProgressBar( 100, 100 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// write "MARKERX" string, meaning that Markers are not saved
|
||||
os->fwrite(markers_skipsave_id, MARKERS_ID_LEN);
|
||||
|
|
|
@ -263,6 +263,11 @@ void SELECTION::save(EMUFILE *os, bool really_save)
|
|||
{
|
||||
if (really_save)
|
||||
{
|
||||
int last_tick = -1;
|
||||
|
||||
setTasProjectProgressBarText("Saving Selection...");
|
||||
setTasProjectProgressBar( 0, historyTotalItems );
|
||||
|
||||
// write "SELECTION" string
|
||||
os->fwrite(selection_save_id, SELECTION_ID_LEN);
|
||||
// write vars
|
||||
|
@ -272,10 +277,20 @@ void SELECTION::save(EMUFILE *os, bool really_save)
|
|||
for (int i = 0; i < historyTotalItems; ++i)
|
||||
{
|
||||
saveSelection(rowsSelectionHistory[(historyStartPos + i) % historySize], os);
|
||||
|
||||
if (i / SAVING_HISTORY_PROGRESSBAR_UPDATE_RATE > last_tick)
|
||||
{
|
||||
setTasProjectProgressBar( i, historyTotalItems );
|
||||
//playback->setProgressbar(i, historyTotalItems);
|
||||
last_tick = i / PROGRESSBAR_UPDATE_RATE;
|
||||
}
|
||||
}
|
||||
// write clipboard_selection
|
||||
saveSelection(splicer->getClipboardSelection(), os);
|
||||
} else
|
||||
|
||||
setTasProjectProgressBar( historyTotalItems, historyTotalItems );
|
||||
}
|
||||
else
|
||||
{
|
||||
// write "SELECTIOX" string
|
||||
os->fwrite(selection_skipsave_id, SELECTION_ID_LEN);
|
||||
|
|
|
@ -17,6 +17,7 @@ Project - Manager of working project
|
|||
------------------------------------------------------------------------------------ */
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
|
||||
#include "fceu.h"
|
||||
#include "movie.h"
|
||||
|
@ -32,6 +33,8 @@ extern void FCEU_PrintError(const char *format, ...);
|
|||
extern bool saveProject(bool save_compact = false);
|
||||
extern bool saveProjectAs(bool save_compact = false);
|
||||
|
||||
static QProgressDialog *progressDialog = NULL;
|
||||
|
||||
TASEDITOR_PROJECT::TASEDITOR_PROJECT()
|
||||
{
|
||||
}
|
||||
|
@ -95,37 +98,51 @@ bool TASEDITOR_PROJECT::save(const char* differentName, bool inputInBinary, bool
|
|||
if (count1 && count2)
|
||||
{
|
||||
// ask user if he wants to fix the checksum before saving
|
||||
char message[2048] = {0};
|
||||
strcpy(message, "Movie ROM:\n");
|
||||
strncat(message, currMovieData.romFilename.c_str(), 2047 - strlen(message));
|
||||
strncat(message, "\nMD5: ", 2047 - strlen(message));
|
||||
strncat(message, md5OfMovie, 2047 - strlen(message));
|
||||
strncat(message, "\n\nCurrent ROM:\n", 2047 - strlen(message));
|
||||
strncat(message, GameInfo->filename, 2047 - strlen(message));
|
||||
strncat(message, "\nMD5: ", 2047 - strlen(message));
|
||||
strncat(message, md5OfRom, 2047 - strlen(message));
|
||||
strncat(message, "\n\nFix the movie header before saving? ", 2047 - strlen(message));
|
||||
//int answer = MessageBox(taseditorWindow.hwndTASEditor, message, "ROM Checksum Mismatch", MB_YESNOCANCEL);
|
||||
//if (answer == IDCANCEL)
|
||||
//{
|
||||
// // cancel saving
|
||||
// return false;
|
||||
//} else if (answer == IDYES)
|
||||
//{
|
||||
std::string message;
|
||||
message.assign("Movie ROM:\n");
|
||||
message.append(currMovieData.romFilename.c_str());
|
||||
message.append("\nMD5: ");
|
||||
message.append(md5OfMovie);
|
||||
message.append("\n\nCurrent ROM:\n");
|
||||
message.append(GameInfo->filename);
|
||||
message.append("\nMD5: ");
|
||||
message.append(md5OfRom);
|
||||
message.append("\n\nFix the movie header before saving? ");
|
||||
|
||||
int ans = QMessageBox::warning( tasWin, QObject::tr("ROM Checksum Mismatch"), QObject::tr(message.c_str()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Cancel );
|
||||
|
||||
if ( QMessageBox::Cancel == ans )
|
||||
{ // cancel saving
|
||||
return false;
|
||||
}
|
||||
else if ( QMessageBox::Yes == ans )
|
||||
{
|
||||
// change ROM data in the movie to current ROM
|
||||
currMovieData.romFilename = GameInfo->filename;
|
||||
currMovieData.romChecksum = GameInfo->MD5;
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
// open file for write
|
||||
EMUFILE_FILE* ofs = 0;
|
||||
if (differentName)
|
||||
{
|
||||
ofs = FCEUD_UTF8_fstream(differentName, "wb");
|
||||
}
|
||||
else
|
||||
{
|
||||
ofs = FCEUD_UTF8_fstream(getProjectFile().c_str(), "wb");
|
||||
}
|
||||
if (ofs)
|
||||
{
|
||||
progressDialog = new QProgressDialog( QObject::tr("Saving TAS Project"), QObject::tr("Cancel"), 0, 100, tasWin );
|
||||
progressDialog->setWindowModality(Qt::WindowModal);
|
||||
progressDialog->setWindowTitle( QObject::tr("Saving TAS Project") );
|
||||
progressDialog->setAutoReset(false);
|
||||
progressDialog->setAutoClose(false);
|
||||
progressDialog->setMinimumDuration(500);
|
||||
progressDialog->setValue(0);
|
||||
|
||||
// change cursor to hourglass
|
||||
//SetCursor(LoadCursor(0, IDC_WAIT));
|
||||
// save fm2 data to the project file
|
||||
|
@ -171,14 +188,20 @@ bool TASEDITOR_PROJECT::save(const char* differentName, bool inputInBinary, bool
|
|||
write32le(selectionOffset, ofs);
|
||||
// finish
|
||||
delete ofs;
|
||||
playback->updateProgressbar();
|
||||
//playback->updateProgressbar();
|
||||
// also set project.changed to false, unless it was SaveCompact
|
||||
if (!differentName)
|
||||
reset();
|
||||
// restore cursor
|
||||
|
||||
if ( progressDialog )
|
||||
{
|
||||
delete progressDialog; progressDialog = NULL;
|
||||
}
|
||||
//taseditorWindow.mustUpdateMouseCursor = true;
|
||||
return true;
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -455,3 +478,25 @@ void setInputType(MovieData& md, int newInputType)
|
|||
taseditorConfig->lastExportedInputType = newInputType;
|
||||
}
|
||||
}
|
||||
|
||||
void setTasProjectProgressBarText( const char *txt )
|
||||
{
|
||||
if ( progressDialog )
|
||||
{
|
||||
progressDialog->setLabelText( QObject::tr(txt) );
|
||||
}
|
||||
}
|
||||
|
||||
void setTasProjectProgressBar( int cur, int max )
|
||||
{
|
||||
if ( progressDialog )
|
||||
{
|
||||
//printf("Set Progress %i / %i \n", cur, max );
|
||||
|
||||
if ( max != progressDialog->maximum() )
|
||||
{
|
||||
progressDialog->setMaximum(max);
|
||||
}
|
||||
progressDialog->setValue(cur);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,3 +79,5 @@ private:
|
|||
|
||||
int getInputType(MovieData& md);
|
||||
void setInputType(MovieData& md, int new_input_type);
|
||||
void setTasProjectProgressBar( int cur, int max );
|
||||
void setTasProjectProgressBarText( const char *txt );
|
||||
|
|
Loading…
Reference in New Issue