Upload manager startup
This commit is contained in:
@@ -21,6 +21,22 @@ NS_BEGIN(Sia)
|
||||
NS_BEGIN(Api)
|
||||
|
||||
typedef std::wstring String;
|
||||
|
||||
class StartupException :
|
||||
public std::exception
|
||||
{
|
||||
public:
|
||||
StartupException(const String& reason) :
|
||||
std::exception(CW2A(reason.c_str()).m_psz)
|
||||
{
|
||||
}
|
||||
|
||||
StartupException(const std::string& reason) :
|
||||
std::exception(reason.c_str())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#define DEFAULT_CONFIG_FILE_PATH L".\\Config\\SiaDriveConfig.json"
|
||||
|
||||
#define Property(type, name, get_access, set_access) \
|
||||
|
@@ -97,11 +97,59 @@ CUploadManager::CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriv
|
||||
{
|
||||
CreateTableIfNotFound(&_uploadDatabase, UPLOAD_TABLE, UPLOAD_TABLE_COLUMNS);
|
||||
|
||||
RecurDeleteFilesByExtentsion(CA2W(siaDriveConfig->GetCacheFolder().c_str()).m_psz, L".siadrive");
|
||||
RecurDeleteFilesByExtentsion(CA2W(siaDriveConfig->GetCacheFolder().c_str()).m_psz, L".siadrive.temp");
|
||||
if (!RecurDeleteFilesByExtentsion(CA2W(siaDriveConfig->GetCacheFolder().c_str()).m_psz, L".siadrive"))
|
||||
{
|
||||
throw StartupException(L"Failed to remove '.siadrive' files");
|
||||
}
|
||||
|
||||
if (!RecurDeleteFilesByExtentsion(CA2W(siaDriveConfig->GetCacheFolder().c_str()).m_psz, L".siadrive.temp"))
|
||||
{
|
||||
throw StartupException(L"Failed to remove '.siadrive.temp' files");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Re-add Copying and Remove
|
||||
SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH_AND_2_STATUS);
|
||||
query.bind("@status1", static_cast<unsigned>(UploadStatus::Copying));
|
||||
query.bind("@status1", static_cast<unsigned>(UploadStatus::Remove));
|
||||
while (query.executeStep())
|
||||
{
|
||||
String siaPath = CA2W(query.getColumn(query.getColumnIndex("sia_path"))).m_psz;
|
||||
String filePath = CA2W(query.getColumn(query.getColumnIndex("file_path"))).m_psz;
|
||||
String siaDriveFilePath = CA2W(query.getColumn(query.getColumnIndex("sd_file_path"))).m_psz;
|
||||
UploadStatus uploadStatus = static_cast<UploadStatus>(query.getColumn(query.getColumnIndex("status")).getUInt());
|
||||
|
||||
String temp = filePath;
|
||||
::PathRemoveFileSpec(&temp[0]);
|
||||
String rootPath = temp;
|
||||
|
||||
// Strip drive specification (i.e. C:\)
|
||||
// TODO If mount to folder is ever enabled, this will need to change
|
||||
String siaDriveFileName = GenerateSha256(&filePath[3]) + L".siadrive";
|
||||
|
||||
String tempSourcePath;
|
||||
tempSourcePath.resize(MAX_PATH + 1);
|
||||
PathCombine(&tempSourcePath[0], rootPath.c_str(), (siaDriveFileName + L".temp").c_str());
|
||||
|
||||
std::lock_guard<std::mutex> l(_fileQueueMutex);
|
||||
if (uploadStatus == UploadStatus::Remove)
|
||||
{
|
||||
_fileQueue.push_back([=]() { this->FileAction(CSiaCurl(GetHostConfig()), siaPath, filePath, nullptr, siaDriveFilePath, true); });
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemoveAdded(siaPath)));
|
||||
}
|
||||
else
|
||||
{
|
||||
_fileQueue.push_back([=]() { this->FileAction(CSiaCurl(GetHostConfig()), siaPath, filePath, tempSourcePath, siaDriveFilePath, false); });
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(NewFileAdded(siaPath, filePath, siaDriveFilePath)));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLite::Exception e)
|
||||
{
|
||||
throw StartupException(e.getErrorStr());
|
||||
}
|
||||
|
||||
// TODO Search for removed
|
||||
// TODO Search for incomplete
|
||||
StartAutoThread();
|
||||
_fileThread.StartAutoThread();
|
||||
}
|
||||
|
@@ -69,6 +69,7 @@ public:
|
||||
|
||||
public:
|
||||
_UploadStatus GetUploadStatus(const String& siaPath);
|
||||
void do_work(String& filePath, String& rootPath);
|
||||
_UploadError AddOrUpdate(const String& siaPath, String filePath);
|
||||
_UploadError Remove(const String& siaPath);
|
||||
};
|
||||
|
Reference in New Issue
Block a user