Skip to content

Instantly share code, notes, and snippets.

@yoyz
Created May 28, 2014 23:28
Show Gist options
  • Save yoyz/b383f1cc37395d92cb60 to your computer and use it in GitHub Desktop.
Save yoyz/b383f1cc37395d92cb60 to your computer and use it in GitHub Desktop.
patch_saveas_20140529
diff --git a/sources/Application/AppWindow.cpp b/sources/Application/AppWindow.cpp
index faa12a2..1128d5c 100644
--- a/sources/Application/AppWindow.cpp
+++ b/sources/Application/AppWindow.cpp
@@ -77,6 +77,7 @@ AppWindow::AppWindow(I_GUIWindowImp &imp):GUIWindow(imp) {
_mixerView=0 ;
_grooveView=0 ;
_closeProject=0 ;
+ _loadAfterSaveAsProject=0 ;
_lastA=0 ;
_lastB=0 ;
_mask=0 ;
@@ -264,10 +265,11 @@ void AppWindow::Flush() {
} ;
void AppWindow::LoadProject(const Path &p) {
-
+ printf("project:%s\n",p.GetPath().c_str());
_root=p ;
_closeProject=false ;
+ _loadAfterSaveAsProject=false;
PersistencyService *persist=PersistencyService::GetInstance() ;
@@ -450,6 +452,11 @@ bool AppWindow::onEvent(GUIEvent &event) {
CloseProject() ;
_isDirty=true ;
}
+ if(_loadAfterSaveAsProject) {
+ CloseProject();
+ _isDirty=true;
+ LoadProject(_newProjectToLoad);
+ }
#ifdef _SHOW_GP2X_
Redraw() ;
#else
@@ -529,12 +536,14 @@ void AppWindow::Update(Observable &o,I_ObservableData *d) {
break ;
}
-/* case VET_LIST_SELECT:
+ case VET_SAVEAS_PROJECT:
{
+ // name hold the new project name
char *name=(char*)ve->GetData() ;
- LoadProject(name) ;
+ _loadAfterSaveAsProject=true;
+ strcpy(_newProjectToLoad,name);
break ;
- } */
+ }
case VET_QUIT_PROJECT:
{
// defer event to after we got out of the view
diff --git a/sources/Application/AppWindow.h b/sources/Application/AppWindow.h
index 4cbf52c..704a4ee 100644
--- a/sources/Application/AppWindow.h
+++ b/sources/Application/AppWindow.h
@@ -77,11 +77,13 @@ private:
bool _isDirty ;
bool _closeProject ;
+ bool _loadAfterSaveAsProject ;
bool _shouldQuit ;
unsigned short _mask ;
unsigned long _lastA ;
unsigned long _lastB ;
char _statusLine[80] ;
+ char _newProjectToLoad[80];
unsigned char _charScreen[1200] ;
unsigned char _charScreenProp[1200] ;
unsigned char _preScreen[1200] ;
diff --git a/sources/Adapters/DEB/System/DEBSystem.cpp b/sources/Adapters/DEB/System/DEBSystem.cpp
index 6e86693..32e2189 100644
--- a/sources/Adapters/DEB/System/DEBSystem.cpp
+++ b/sources/Adapters/DEB/System/DEBSystem.cpp
@@ -52,9 +52,8 @@ void DEBSystem::Boot(int argc,char **argv) {
{
strcpy(buff,".");
}
- Path::SetAlias("bin",dirname(buff)) ;
-
- Path::SetAlias("root","bin:..") ;
+ Path::SetAlias("bin",".") ;
+ Path::SetAlias("root",".") ;
#ifdef _DEBUG
Trace::GetInstance()->SetLogger(*(new StdOutLogger()));
diff --git a/sources/System/FileSystem/FileSystem.cpp b/sources/System/FileSystem/FileSystem.cpp
index 9f73a4e..27d6e9e 100644
--- a/sources/System/FileSystem/FileSystem.cpp
+++ b/sources/System/FileSystem/FileSystem.cpp
@@ -186,10 +187,27 @@ int FileSystemService::Copy(const Path &src,const Path &dst)
char buffer[bufsize];
int count=0;
int nbwrite=-1;
-
+
FileSystem * fs=FileSystem::GetInstance() ;
I_File * isrc=fs->Open(src.GetPath().c_str(),"r");
I_File * idst=fs->Open(dst.GetPath().c_str(),"w");
+
+ Trace::Log("FS","FileSystemService::Copy ");
+ Trace::Log("FS",src.GetPath().c_str());
+ Trace::Log("FS",dst.GetPath().c_str());
+ if (isrc)
+ Trace::Log("FS","src open ok");
+ else {
+ Trace::Log("FS","src open fail");
+ return nbwrite;
+ }
+ if (idst)
+ Trace::Log("FS","dst open ok");
+ else {
+ Trace::Log("FS","dst open fail");
+ return nbwrite;
+ }
+
while (count=isrc->Read(buffer,sizeof(char),bufsize))
{
@@ -199,6 +217,6 @@ int FileSystemService::Copy(const Path &src,const Path &dst)
isrc->Close();
idst->Close();
-
return nbwrite;
}
+
diff --git a/sources/System/FileSystem/FileSystem.h b/sources/System/FileSystem/FileSystem.h
index a915ffc..15c260c 100644
--- a/sources/System/FileSystem/FileSystem.h
+++ b/sources/System/FileSystem/FileSystem.h
@@ -108,9 +108,11 @@ public:
#define FS_FOPEN(a,b) FileSystem::GetInstance()->Open(a,b)
+
class FileSystemService {
public:
int Copy(const Path &src,const Path &dst);
};
#endif
+
diff --git a/sources/Application/Views/ProjectView.cpp b/sources/Application/Views/ProjectView.cpp
index 573b940..6064191 100644
--- a/sources/Application/Views/ProjectView.cpp
+++ b/sources/Application/Views/ProjectView.cpp
@@ -6,13 +6,85 @@
#include "System/System/System.h"
#include "Services/Midi/MidiService.h"
#include "Application/Views/ModalDialogs/MessageBox.h"
-
-#define ACTION_PURGE MAKE_FOURCC('P','U','R','G')
-#define ACTION_SAVE MAKE_FOURCC('S','A','V','E')
-#define ACTION_LOAD MAKE_FOURCC('L','O','A','D')
-#define ACTION_QUIT MAKE_FOURCC('Q','U','I','T')
+#include "Application/Views/ModalDialogs/NewProjectDialog.h"
+#include "Application/Views/ModalDialogs/SelectProjectDialog.h"
+
+#define ACTION_PURGE MAKE_FOURCC('P','U','R','G')
+#define ACTION_SAVE MAKE_FOURCC('S','A','V','E')
+#define ACTION_SAVE_AS MAKE_FOURCC('S','V','A','S')
+#define ACTION_LOAD MAKE_FOURCC('L','O','A','D')
+#define ACTION_QUIT MAKE_FOURCC('Q','U','I','T')
#define ACTION_PURGE_INSTRUMENT MAKE_FOURCC('P','R','G','I')
-#define ACTION_TEMPO_CHANGED MAKE_FOURCC('T','E','M','P')
+#define ACTION_TEMPO_CHANGED MAKE_FOURCC('T','E','M','P')
+
+
+
+static void SaveAsProjectCallback(View &v,ModalView &dialog) {
+ bool copyOk=true;
+ FileSystemService FSS;
+ NewProjectDialog &npd=(NewProjectDialog &)dialog ;
+
+ // npd.GetName will store the new project name
+ if (dialog.GetReturnCode()>0) {
+ std::string str_dstprjdir=npd.GetName();
+ std::string str_dstsmpdir=npd.GetName()+"/samples";
+
+ Path path_dstprjdir = Path(str_dstprjdir.c_str());
+ Path path_dstsmpdir = Path(str_dstsmpdir.c_str());
+ Path path_srcprjdir("project:");
+ Path path_srcsmpdir("project:samples");
+
+ Path path_srclgptdatsav=path_srcprjdir.GetPath()+"lgptsav.dat";
+ Path path_dstlgptdatsav=path_dstprjdir.GetPath()+"/lgptsav.dat";
+
+ // Create Dir if not Exist
+ if (path_dstprjdir.Exists()) {
+ Trace::Log("FS","Save As : Dst Dir Exist, replacing content");
+ } else {
+ Trace::Log("FS","Save As : Dst Dir Does not Exist, creating save as directory ");
+ Result result = FileSystem::GetInstance()->MakeDir(path_dstprjdir.GetPath().c_str()) ;
+ RETURN_IF_FAILED_MESSAGE(result,"Failed to create project dir");
+ result = FileSystem::GetInstance()->MakeDir(path_dstsmpdir.GetPath().c_str()) ;
+ RETURN_IF_FAILED_MESSAGE(result,"Failed to create sample dir");
+ }
+
+ // Copy lgptdat file from source dir to the dest directory
+ if (FSS.Copy(path_srclgptdatsav,path_dstlgptdatsav)<=0) {
+ Trace::Log("FS","Copying lgptdat.sav file failed ");
+ copyOk=false;
+ }
+
+ // Copy all sample file from source dir to the dest directory
+ I_Dir *idir_srcsmpdir=FileSystem::GetInstance()->Open(path_srcsmpdir.GetPath().c_str()) ;
+ if (idir_srcsmpdir) {
+ idir_srcsmpdir->GetContent("*") ;
+ idir_srcsmpdir->Sort() ;
+ IteratorPtr<Path>it(idir_srcsmpdir->GetIterator()) ;
+ for (it->Begin();!it->IsDone();it->Next()) {
+ Path &current=it->CurrentItem() ;
+ if (current.IsFile()) {
+ Path dstfile = Path(str_dstsmpdir+"/"+current.GetName());
+ Path srcfile = Path(current.GetPath());
+ //check if the copy was done
+ //Try to fallback to srcprjdir with log if it failed
+ if (FSS.Copy(srcfile.GetPath(),dstfile.GetPath())==-1) {
+ Trace::Log("FS","copying sample failed");
+ path_dstprjdir=path_srcprjdir;
+ copyOk=false;
+ break;
+ }
+ }
+ }
+ }
+ //copy worked => go to the new project,
+ //other case => project screen
+ if (copyOk)
+ ((ProjectView &)v).OnSaveAsProject(str_dstprjdir.c_str()) ;
+ else
+ return;
+ }
+}
+
static void LoadCallback(View &v,ModalView &dialog) {
if (dialog.GetReturnCode()==MBL_YES) {
@@ -75,6 +147,11 @@ ProjectView::ProjectView(GUIWindow &w,ViewData *data):FieldView(w,data) {
a1->AddObserver(*this) ;
T_SimpleList<UIField>::Insert(a1) ;
+ position._y+=1 ;
+ a1=new UIActionField("Save As",ACTION_SAVE_AS,position) ;
+ a1->AddObserver(*this) ;
+ T_SimpleList<UIField>::Insert(a1) ;
+
v=project_->FindVariable(VAR_MIDIDEVICE) ;
NAssert(v) ;
position._y+=2 ;
@@ -86,6 +163,8 @@ ProjectView::ProjectView(GUIWindow &w,ViewData *data):FieldView(w,data) {
a1->AddObserver(*this) ;
T_SimpleList<UIField>::Insert(a1) ;
+
+
}
ProjectView::~ProjectView() {
@@ -169,6 +248,20 @@ void ProjectView::Update(Observable &,I_ObservableData *data) {
DoModal(mb) ;
}
break ;
+ case ACTION_SAVE_AS:
+ if (!player->IsRunning()) {
+ PersistencyService *service=PersistencyService::GetInstance() ;
+ service->Save() ;
+ //MessageBox *mb=new MessageBox(*this,"Load song and lose changes ?",MBBF_YES|MBBF_NO) ;
+ NewProjectDialog *mb=new NewProjectDialog(*this) ;
+ DoModal(mb,SaveAsProjectCallback) ;
+
+ } else {
+ MessageBox *mb=new MessageBox(*this,"Not while playing",MBBF_OK) ;
+ DoModal(mb) ;
+ }
+ break ;
+
case ACTION_LOAD:
{
if (!player->IsRunning()) {
@@ -211,8 +304,18 @@ void ProjectView::OnLoadProject() {
NotifyObservers(&ve) ;
} ;
+
+void ProjectView::OnSaveAsProject(char * data) {
+ ViewEvent ve(VET_SAVEAS_PROJECT,data) ;
+ SetChanged();
+ NotifyObservers(&ve) ;
+} ;
+
+
void ProjectView::OnQuit() {
ViewEvent ve(VET_QUIT_APP) ;
SetChanged();
NotifyObservers(&ve) ;
} ;
+
+
diff --git a/sources/Application/Views/ProjectView.h b/sources/Application/Views/ProjectView.h
index d48a1d7..1f9474c 100644
--- a/sources/Application/Views/ProjectView.h
+++ b/sources/Application/Views/ProjectView.h
@@ -21,6 +21,7 @@ public:
void Update(Observable &,I_ObservableData *) ;
void OnLoadProject() ;
+ void OnSaveAsProject(char * data) ;
void OnPurgeInstruments(bool removeFromDisk) ;
void OnQuit() ;
diff --git a/sources/Adapters/PSP/FileSystem/PSPFileSystem.cpp b/sources/Adapters/PSP/FileSystem/PSPFileSystem.cpp
index 195963f..f2ce810 100644
--- a/sources/Adapters/PSP/FileSystem/PSPFileSystem.cpp
+++ b/sources/Adapters/PSP/FileSystem/PSPFileSystem.cpp
@@ -4,7 +4,7 @@
#include <string.h>
#include <stdarg.h>
#include <string>
-#include <Application/utils/wildcard.h>
+#include <Application/Utils/wildcard.h>
#include <sys/dir.h>
#include <sys/stat.h>
@@ -177,4 +177,4 @@ Result PSPFileSystem::MakeDir(const char *path) {
return Result(oss.str());
}
return Result::NoError;
-}
\ No newline at end of file
+}
diff --git a/sources/Application/Views/BaseClasses/ViewEvent.h b/sources/Application/Views/BaseClasses/ViewEvent.h
index afa0432..151760c 100644
--- a/sources/Application/Views/BaseClasses/ViewEvent.h
+++ b/sources/Application/Views/BaseClasses/ViewEvent.h
@@ -5,9 +5,9 @@
enum ViewEventType {
VET_SWITCH_VIEW,
- VET_PLAYER_POSITION_UPDATE,
- VET_LIST_SELECT,
- VET_QUIT_PROJECT,
+ VET_PLAYER_POSITION_UPDATE,
+ VET_SAVEAS_PROJECT,
+ VET_QUIT_PROJECT,
VET_UPDATE,
VET_QUIT_APP
} ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment