Stamp fix button to bring back deleted stamps

This commit is contained in:
jacob1 2012-10-01 22:00:57 -04:00 committed by Simon Robertshaw
parent cb8efcd0f9
commit d45dd605e9
9 changed files with 56 additions and 2 deletions

View File

@ -21,11 +21,11 @@
#endif #endif
#ifndef MINOR_VERSION #ifndef MINOR_VERSION
#define MINOR_VERSION 4 #define MINOR_VERSION 9
#endif #endif
#ifndef BUILD_NUM #ifndef BUILD_NUM
#define BUILD_NUM 213 #define BUILD_NUM 232
#endif #endif
#ifndef SNAPSHOT_ID #ifndef SNAPSHOT_ID

View File

@ -8,6 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <deque> #include <deque>
#include <fstream> #include <fstream>
#include <dirent.h>
#ifdef MACOSX #ifdef MACOSX
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
@ -910,6 +911,28 @@ void Client::updateStamps()
return; return;
} }
void Client::UnDeleteStamps()
{
DIR * directory;
struct dirent * entry;
directory = opendir("stamps");
if (directory != NULL)
{
stampIDs.clear();
while (entry = readdir(directory))
{
if(strncmp(entry->d_name, "..", 3) && strncmp(entry->d_name, ".", 2) && strcmp(entry->d_name, ".stm"))
{
char stampname[11];
strncpy(stampname, entry->d_name, 10);
stampIDs.push_front(stampname);
}
}
closedir(directory);
updateStamps();
}
}
int Client::GetStampsCount() int Client::GetStampsCount()
{ {
return stampIDs.size(); return stampIDs.size();

View File

@ -112,6 +112,7 @@ public:
void DeleteStamp(std::string stampID); void DeleteStamp(std::string stampID);
std::string AddStamp(GameSave * saveData); std::string AddStamp(GameSave * saveData);
std::vector<std::string> GetStamps(int start, int count); std::vector<std::string> GetStamps(int start, int count);
void Client::UnDeleteStamps();
int GetStampsCount(); int GetStampsCount();
SaveFile * GetFirstStamp(); SaveFile * GetFirstStamp();

View File

@ -89,6 +89,12 @@ void LocalBrowserController::removeSelectedC()
new TaskWindow("Removing saves", new RemoveSavesTask(this, selected)); new TaskWindow("Removing saves", new RemoveSavesTask(this, selected));
} }
void LocalBrowserController::UnDeleteStamps()
{
browserModel->UnDeleteStamps();
browserModel->UpdateSavesList(browserModel->GetPageNum());
}
void LocalBrowserController::RefreshSavesList() void LocalBrowserController::RefreshSavesList()
{ {
ClearSelection(); ClearSelection();

View File

@ -27,6 +27,7 @@ public:
void removeSelectedC(); void removeSelectedC();
void ClearSelection(); void ClearSelection();
void Selected(std::string stampID, bool selected); void Selected(std::string stampID, bool selected);
void UnDeleteStamps();
void RefreshSavesList(); void RefreshSavesList();
void OpenSave(SaveFile * stamp); void OpenSave(SaveFile * stamp);
void SetStamp(); void SetStamp();

View File

@ -87,6 +87,11 @@ void LocalBrowserModel::UpdateSavesList(int pageNumber)
notifySavesListChanged(); notifySavesListChanged();
} }
void LocalBrowserModel::UnDeleteStamps()
{
Client::Ref().UnDeleteStamps();
}
int LocalBrowserModel::GetPageCount() int LocalBrowserModel::GetPageCount()
{ {
return std::max(1, (int)(std::ceil(float(Client::Ref().GetStampsCount())/20.0f))); return std::max(1, (int)(std::ceil(float(Client::Ref().GetStampsCount())/20.0f)));

View File

@ -32,6 +32,7 @@ public:
void AddObserver(LocalBrowserView * observer); void AddObserver(LocalBrowserView * observer);
std::vector<SaveFile *> GetSavesList(); std::vector<SaveFile *> GetSavesList();
void UpdateSavesList(int pageNumber); void UpdateSavesList(int pageNumber);
void UnDeleteStamps();
SaveFile * GetSave(); SaveFile * GetSave();
void SetSave(SaveFile * newStamp); void SetSave(SaveFile * newStamp);
std::vector<std::string> GetSelected() { return selected; } std::vector<std::string> GetSelected() { return selected; }

View File

@ -16,6 +16,7 @@
#include "interface/Keys.h" #include "interface/Keys.h"
#include "dialogues/ErrorMessage.h" #include "dialogues/ErrorMessage.h"
#include "dialogues/ConfirmPrompt.h"
#include "LocalBrowserController.h" #include "LocalBrowserController.h"
#include "LocalBrowserModel.h" #include "LocalBrowserModel.h"
#include "LocalBrowserModelException.h" #include "LocalBrowserModelException.h"
@ -25,10 +26,12 @@ LocalBrowserView::LocalBrowserView():
{ {
nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95"); nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95");
previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev"); previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev");
undeleteButton = new ui::Button(ui::Point(XRES+BARSIZE-122, YRES+MENUSIZE-18), ui::Point(60, 16), "Stamp Fix");
infoLabel = new ui::Label(ui::Point(51, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-102, 16), "Loading..."); infoLabel = new ui::Label(ui::Point(51, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-102, 16), "Loading...");
AddComponent(infoLabel); AddComponent(infoLabel);
AddComponent(nextButton); AddComponent(nextButton);
AddComponent(previousButton); AddComponent(previousButton);
AddComponent(undeleteButton);
class NextPageAction : public ui::ButtonAction class NextPageAction : public ui::ButtonAction
{ {
@ -58,6 +61,19 @@ LocalBrowserView::LocalBrowserView():
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
previousButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; previousButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
class UndeleteAction : public ui::ButtonAction
{
LocalBrowserView * v;
public:
UndeleteAction(LocalBrowserView * _v) { v = _v; }
void ActionCallback(ui::Button * sender)
{
if(ConfirmPrompt::Blocking("Bring back deleted stamps", "Versions 83.1-83.8 had a bug where stamps past page 3 were deleted from the list. Click continue to bring these back and read every stamp in the stamps/ folder.\n\nWARNING:\nThis will also bring back all stamps deleted before version 74.2 (March 2012)", "Continue"))
v->c->UnDeleteStamps();
}
};
undeleteButton->SetActionCallback(new UndeleteAction(this));
class RemoveSelectedAction : public ui::ButtonAction class RemoveSelectedAction : public ui::ButtonAction
{ {
LocalBrowserView * v; LocalBrowserView * v;

View File

@ -23,6 +23,7 @@ class LocalBrowserModel;
class LocalBrowserView: public ui::Window { class LocalBrowserView: public ui::Window {
LocalBrowserController * c; LocalBrowserController * c;
std::vector<ui::SaveButton*> stampButtons; std::vector<ui::SaveButton*> stampButtons;
ui::Button * undeleteButton;
ui::Button * previousButton; ui::Button * previousButton;
ui::Button * nextButton; ui::Button * nextButton;
ui::Label * infoLabel; ui::Label * infoLabel;