NEW: support send to sd card with cloud

JIRA: STUDIO-7378

Change-Id: I95fee50db29825e508d276d52c7a3e85e1347ebd
(cherry picked from commit 13db95ceb4f18b8cbce1e67447eeaa6ee36cc8ad)
This commit is contained in:
Kunlong Ma
2024-09-04 14:09:32 +08:00
committed by Noisyfox
parent ccfb28ad10
commit 139826677a
6 changed files with 739 additions and 82 deletions

View File

@@ -22,39 +22,52 @@ wxDECLARE_EVENT(EVT_FILE_CHANGED, wxCommandEvent);
wxDECLARE_EVENT(EVT_SELECT_CHANGED, wxCommandEvent);
wxDECLARE_EVENT(EVT_THUMBNAIL, wxCommandEvent);
wxDECLARE_EVENT(EVT_DOWNLOAD, wxCommandEvent);
wxDECLARE_EVENT(EVT_MEDIA_ABILITY_CHANGED, wxCommandEvent);
wxDECLARE_EVENT(EVT_UPLOADING, wxCommandEvent);
wxDECLARE_EVENT(EVT_UPLOAD_CHANGED, wxCommandEvent);
class PrinterFileSystem : public wxEvtHandler, public boost::enable_shared_from_this<PrinterFileSystem>, BambuLib
{
static const int CTRL_TYPE = 0x3001;
enum {
LIST_INFO = 0x0001,
SUB_FILE = 0x0002,
FILE_DEL = 0x0003,
FILE_DOWNLOAD = 0X0004,
NOTIFY_FIRST = 0x0100,
LIST_CHANGE_NOTIFY = 0x0100,
LIST_RESYNC_NOTIFY = 0x0101,
TASK_CANCEL = 0x1000
LIST_INFO = 0x0001,
SUB_FILE = 0x0002,
FILE_DEL = 0x0003,
FILE_DOWNLOAD = 0x0004,
FILE_UPLOAD = 0x0005,
REQUEST_MEDIA_ABILITY = 0x0007,
NOTIFY_FIRST = 0x0100,
LIST_CHANGE_NOTIFY = 0x0100,
LIST_RESYNC_NOTIFY = 0x0101,
TASK_CANCEL = 0x1000
};
public:
enum {
SUCCESS = 0,
CONTINUE = 1,
ERROR_JSON = 2,
ERROR_PIPE = 3,
ERROR_CANCEL = 4,
ERROR_RES_BUSY = 5,
FILE_NO_EXIST = 10,
FILE_NAME_INVALID = 11,
FILE_SIZE_ERR = 12,
FILE_OPEN_ERR = 13,
FILE_READ_WRITE_ERR = 14,
FILE_CHECK_ERR = 15,
FILE_TYPE_ERR = 16,
STORAGE_UNAVAILABLE = 17,
SUCCESS = 0,
CONTINUE = 1,
ERROR_JSON = 2,
ERROR_PIPE = 3,
ERROR_CANCEL = 4,
ERROR_RES_BUSY = 5,
ERROR_TIME_OUT = 6,
FILE_NO_EXIST = 10,
FILE_NAME_INVALID = 11,
FILE_SIZE_ERR = 12,
FILE_OPEN_ERR = 13,
FILE_READ_WRITE_ERR = 14,
FILE_CHECK_ERR = 15,
FILE_TYPE_ERR = 16,
STORAGE_UNAVAILABLE = 17,
API_VERSION_UNSUPPORT = 18,
FILE_EXIST = 19,
STORAGE_SPACE_NOT_ENOUGH = 20,
FILE_CREATE_ERR = 21,
FILE_WRITE_ERR = 22,
MD5_COMPARE_ERR = 23,
FILE_RENAME_ERR = 24,
SEND_ERR = 25,
};
@@ -90,12 +103,28 @@ public:
template<typename T> using Callback = std::function<void(int, T)>;
enum Flags {
FF_SELECT = 1,
FF_THUMNAIL = 2, // Thumbnail ready
FF_DOWNLOAD = 4, // Request download
FF_DELETED = 8, // Request delete
FF_FETCH_MODEL = 16,// Request model
FF_THUMNAIL_RETRY = 0x100, // Thumbnail need retry
FF_SELECT = 1,
FF_THUMNAIL = 2, // Thumbnail ready
FF_DOWNLOAD = 4, // Request download
FF_DELETED = 8, // Request delete
FF_FETCH_MODEL = 16, // Request model
FF_UPLOADING = 1 << 5, // File uploading
FF_UPLOADDONE = 1 << 6, // File upload done
FF_UPLOADCANCEL = 1 << 7, // File upload cancel
FF_THUMNAIL_RETRY = 0x100, // Thumbnail need retry
};
enum UploadStatus
{
Uploading = 1 << 0,
UploadDone = 1 << 1,
UploadCancel = 1 << 2,
};
enum RequestMediaAbilityStatus
{
S_SUCCESS,
S_FAILED
};
struct Progress
@@ -106,6 +135,7 @@ public:
};
struct Download;
struct Upload;
struct File
{
@@ -128,9 +158,23 @@ public:
friend bool operator<(File const & l, File const & r) { return l.time > r.time; }
};
struct UploadFile
{
std::string name;
std::string path;
std::string select_storage;
int flags{0};
boost::uint32_t size{0};
boost::uint32_t chunk_size{0}; // KB
std::unique_ptr<Upload> upload;
bool IsUploading() const { return flags & FF_UPLOADING; }
};
struct Void {};
typedef std::vector<File> FileList;
typedef std::vector<std::string> MediaAbilityList;
void ListAllFiles();
@@ -185,6 +229,16 @@ public:
void Stop(bool quit = false);
boost::uint32_t RequestMediaAbility(int api_version);
void RequestUploadFile();
MediaAbilityList GetMediaAbilityList() const;
void SetUploadFile(const std::string& path, const std::string& name, const std::string& select_storage);
void CancelUploadTask(bool send_cancel_req = true);
private:
void BuildGroups();
@@ -217,13 +271,14 @@ private:
typedef std::function<int(int, json const &resp, unsigned char const *data)> callback_t2;
template <typename T>
boost::uint32_t SendRequest(int type, json const& req, Translator<T> const& translator, Callback<T> const& callback)
typedef std::function<int(std::string &msg)> callback_t3;
template<typename T> boost::uint32_t SendRequest(int type, json const &req, Translator<T> const &translator, Callback<T> const &callback)
{
auto c = [translator, callback, this](int result, json const &resp, unsigned char const *data) -> int
{
T t;
if (result == 0 || result == CONTINUE) {
if (result == 0 || result == CONTINUE || result == FILE_EXIST) {
try {
int n = (translator != nullptr) ? translator(resp, t, data) : 0;
result = n == 0 ? result : n;
@@ -289,6 +344,8 @@ private:
void PostCallback(std::function<void(void)> const & callback);
int UploadFileTask(std::shared_ptr<UploadFile> upload_file, boost::uint64_t seq, std::string &msg);
protected:
FileType m_file_type = F_INVALID_TYPE;
std::string m_file_storage;
@@ -298,6 +355,7 @@ protected:
std::vector<size_t> m_group_year;
std::vector<size_t> m_group_month;
std::vector<int> m_group_flags;
std::shared_ptr<UploadFile> m_upload_file;
private:
size_t m_select_count = 0;
@@ -315,6 +373,7 @@ private:
boost::uint32_t m_sequence = 0;
boost::uint32_t m_download_seq = 0;
boost::uint32_t m_fetch_model_seq = 0;
boost::uint32_t m_upload_seq = 0;
std::deque<std::string> m_messages;
std::deque<callback_t2> m_callbacks;
std::deque<callback_t2> m_notifies;
@@ -324,6 +383,9 @@ private:
boost::thread m_recv_thread;
Status m_status;
int m_last_error = 0;
MediaAbilityList m_media_ability_list;
std::map<boost::uint32_t, callback_t3> m_produce_message_cb_map;
};
#endif // !slic3r_GUI_PrinterFileSystem_h_