2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2025-07-04 04:45:14 +08:00
|
|
|
// Copyright (C) 2019-2025 Igara Studio S.A.
|
2018-07-07 13:47:42 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2012-08-23 08:05:02 +08:00
|
|
|
|
2015-04-06 05:51:43 +08:00
|
|
|
#ifndef APP_CRASH_DATA_RECOVERY_H_INCLUDED
|
|
|
|
#define APP_CRASH_DATA_RECOVERY_H_INCLUDED
|
2014-03-30 06:40:17 +08:00
|
|
|
#pragma once
|
2012-08-23 08:05:02 +08:00
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
#include "app/crash/recovery_config.h"
|
2015-04-06 05:51:43 +08:00
|
|
|
#include "app/crash/session.h"
|
2012-08-23 08:05:02 +08:00
|
|
|
#include "base/disable_copying.h"
|
2019-05-27 22:10:52 +08:00
|
|
|
#include "obs/signal.h"
|
2012-08-23 08:05:02 +08:00
|
|
|
|
2021-04-14 02:35:34 +08:00
|
|
|
#include <atomic>
|
2019-05-27 22:10:52 +08:00
|
|
|
#include <mutex>
|
|
|
|
#include <thread>
|
2015-04-06 05:51:43 +08:00
|
|
|
#include <vector>
|
2014-07-29 11:53:24 +08:00
|
|
|
|
2012-08-23 08:05:02 +08:00
|
|
|
namespace app {
|
2018-07-07 13:47:42 +08:00
|
|
|
class Context;
|
2015-04-06 05:51:43 +08:00
|
|
|
namespace crash {
|
2015-04-06 23:06:50 +08:00
|
|
|
class BackupObserver;
|
2012-08-23 08:05:02 +08:00
|
|
|
|
2015-04-06 23:06:50 +08:00
|
|
|
class DataRecovery {
|
2012-08-23 08:05:02 +08:00
|
|
|
public:
|
2015-04-06 05:51:43 +08:00
|
|
|
typedef std::vector<SessionPtr> Sessions;
|
|
|
|
|
2018-07-07 13:47:42 +08:00
|
|
|
DataRecovery(Context* context);
|
2012-08-23 08:05:02 +08:00
|
|
|
~DataRecovery();
|
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
// Launches the thread to search for sessions.
|
|
|
|
void launchSearch();
|
|
|
|
|
2019-05-28 04:53:22 +08:00
|
|
|
bool isSearching() const { return m_searching; }
|
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
// Returns true if there is at least one sessions with sprites to
|
|
|
|
// recover (i.e. a crashed session were changes weren't saved)
|
|
|
|
bool hasRecoverySessions() const;
|
|
|
|
|
2016-11-08 04:47:53 +08:00
|
|
|
Session* activeSession() { return m_inProgress.get(); }
|
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
// Returns a copy of the list of sessions that can be recovered.
|
|
|
|
Sessions sessions();
|
|
|
|
|
2025-07-04 04:45:14 +08:00
|
|
|
bool isRunningSession(const SessionPtr& session) const;
|
|
|
|
|
2019-05-27 22:10:52 +08:00
|
|
|
// Triggered in the UI-thread from the m_thread using an
|
|
|
|
// ui::execute_from_ui_thread() when the list of sessions is ready
|
|
|
|
// to be used.
|
|
|
|
obs::signal<void()> SessionsListIsReady;
|
2012-08-23 08:05:02 +08:00
|
|
|
|
|
|
|
private:
|
2019-05-27 22:10:52 +08:00
|
|
|
// Executed from m_thread to search for the list of sessions.
|
|
|
|
void searchForSessions();
|
|
|
|
|
|
|
|
std::string m_sessionsDir;
|
|
|
|
mutable std::mutex m_sessionsMutex;
|
|
|
|
std::thread m_thread;
|
|
|
|
RecoveryConfig m_config;
|
2015-04-06 05:51:43 +08:00
|
|
|
Sessions m_sessions;
|
|
|
|
SessionPtr m_inProgress;
|
2015-04-06 23:06:50 +08:00
|
|
|
BackupObserver* m_backup;
|
2021-04-14 02:35:34 +08:00
|
|
|
std::atomic<bool> m_searching;
|
2012-08-23 08:05:02 +08:00
|
|
|
|
|
|
|
DISABLE_COPYING(DataRecovery);
|
|
|
|
};
|
|
|
|
|
2015-04-06 05:51:43 +08:00
|
|
|
} // namespace crash
|
2012-08-23 08:05:02 +08:00
|
|
|
} // namespace app
|
|
|
|
|
|
|
|
#endif
|