56 #include <wx/filename.h>
57 #include <wx/msgdlg.h>
77 m_Interval = interval;
89 if (path.empty())
return false;
91 if (wxFileExists(path)) {
92 if (!wxRemoveFile(path)) {
99 if (wxDirExists(path)) {
100 if (!wxFileName::Rmdir(path, wxPATH_RMDIR_RECURSIVE)) {
117 if (path.empty() || !wxDirExists(path))
return false;
122 if (!fname.FileExists())
return false;
125 wxMessageBox(
wxT(
"Application crash detected on the previous launch.\n")
126 wxT(
"Do you want Genome Workbench to try to load the last saved data?"),
127 wxT(
"Exception"), wxOK | wxCANCEL | wxICON_EXCLAMATION)) {
136 wxT(
"Restoring workspace..."));
137 }
NCBI_CATCH(
"CWorkspaceAutoSaver::x_RestoreWorkspace");
147 if (doc && doc->IsLoaded()) {
156 catch (
const exception& e) {
164 if (!
m_Err.empty()) {
167 wxT(
"Error"), wxOK|wxICON_ERROR);
176 if (path.empty() || !wxDirExists(path))
return;
200 if (!it->IsSetFilename())
202 string fileName = it->GetFilename();
207 if (!fileName.empty() && sscanf(fileName.c_str(),
format.c_str(), &counter) == 1)
209 size_t pos = fileName.find(
"|");
210 if (pos != string::npos && pos != 0) {
211 string projFile = fileName.substr(0, pos);
212 it->SetFilename(fileName.substr(pos + 1));
213 fname.SetFullName(projFile);
214 unique_ptr<CNcbiIfstream> istr(
new CNcbiIfstream(fname.GetFullPath().fn_str(), ios::binary|
ios::in));
215 it->Load(*istr, &canceled);
224 vector<CGBProjectHandle::TId> ids = ws->GetUnloadedProjects();
226 ITERATE(vector<CGBProjectHandle::TId>, it2, ids) {
233 task_srv->AddTask(*task);
238 }
catch (
const exception& e) {
242 if (!
m_Err.empty()) {
250 if (path.empty())
return;
262 if (!wxFileName::DirExists(path) && !wxFileName::Mkdir(path)) {
279 string projFile(
buf);
281 string fileName = projFile +
"|";
282 if (it->IsSetFilename())
283 fileName += it->GetFilename();
284 it->SetFilename(fileName);
286 fname.SetFullName(projFile);
287 CTime time = it->GetDescr().GetModified_date().AsCTime();
288 string filePath(fname.GetFullPath().ToUTF8());
293 CNcbiOfstream ostr(fname.GetFullPath().fn_str(), ios::binary);
303 it->SetProject().SetDescr().SetModifiedDate(time);
315 if (it->IsSetFilename())
316 fileName = it->GetFilename();
320 if (!fileName.empty() && sscanf(fileName.c_str(),
format.c_str(), &counter) == 1)
322 size_t pos = fileName.find(
"|");
323 if (pos != string::npos)
324 it->SetFilename(fileName.substr(pos + 1));
360 wxT(
"Saving workspace copy..."));
361 }
NCBI_CATCH(
"CWorkspaceAutoSaver::x_SaveWorkspace");
364 size_t elapsed = (size_t)timer.
Elapsed();
User-defined methods of the data storage class.
User-defined methods of the data storage class.
std::invoke_result< _Fty, ICanceled & >::type GUI_AsyncExec(_Fty &&_Fnarg, const wxString &msg=wxT("Accessing network..."))
CAppTaskService - Application Task Service.
static bool InsideAsyncCall()
CEvent - generic event implementation TODO TODO - Attachments.
virtual void CreateProjectScope()
CProjectService - a service providing API for operations with Workspaces and Projects.
CRef< objects::CGBWorkspace > m_Workspace
the only Workspace
CRef< objects::CGBWorkspace > x_LoadWorkspace(const wxString &filename)
void ResetWorkspace()
release the current workspace and all its contents TODO - review
CRef< objects::CGBWorkspace > GetGBWorkspace()
void x_ReloadProjectTreeView()
static wxString ResolvePath(const wxString &path, const wxString &rel_name)
Utility function to hide the platform specifics of locating our standard directories and files.
Template class for iteration on objects of class C (non-medifiable version)
Template class for iteration on objects of class C.
IServiceLocator & m_ServiceLocator
void x_RestoreWorkspace(ICanceled &canceled)
void x_SaveWorkspace(ICanceled &canceled)
bool CheckCrash(ERestoreMode mode)
Interface for testing cancellation request in a long lasting operation.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
void Error(CExceptionArgs_Base &args)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
const string & GetMsg(void) const
Get message string.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
void Info(CExceptionArgs_Base &args)
bool IsNewer(time_t tm, EIfAbsent if_absent) const
Check if the current entry is newer than a specified date/time.
@ eIfAbsent_NotNewer
Deem absent entry to be "older".
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
void Post(CRef< CEvent > evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Handles an event asynchronously (process and/or dispatch).
#define ON_EVENT(type, id, handler)
#define END_EVENT_MAP()
Ends definition of Command Map.
#define BEGIN_EVENT_MAP(thisClass, baseClass)
Begins definition of Command Map for CEventHandler-derived class.
ESerialDataFormat
Data file format.
@ eSerial_AsnText
ASN.1 text.
@ eSerial_AsnBinary
ASN.1 binary.
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
virtual bool IsCanceled(void) const =0
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
double Elapsed(void) const
Return time elapsed since first Start() or last Restart() call (in seconds).
void Stop(void)
Suspend the timer.
void Start(void)
Start the timer.
@ eCurrent
Use current time. See also CCurrentTime.
TProjects & SetProjects(void)
Assign a value to Projects data member.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
std::istream & in(std::istream &in_, double &x_)
const wxChar * kTemsWsDir
const char * kFailedService
const char * kProjTemplate
wxString ToWxString(const string &s)