Upload manager changes
This commit is contained in:
@@ -91,7 +91,7 @@ void CSiaApi::_CSiaRenter::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDrive
|
||||
|
||||
std::uint32_t totalProgress = std::accumulate(std::next(fileList.begin()), fileList.end(), fileList[0]->GetUploadProgress(), [](const std::uint32_t& progress, const CSiaFilePtr& file)
|
||||
{
|
||||
return progress + file->GetUploadProgress();
|
||||
return progress + min(100, file->GetUploadProgress());
|
||||
}) / fileList.size();
|
||||
|
||||
SetTotalUsedBytes(total);
|
||||
|
@@ -5,12 +5,33 @@
|
||||
|
||||
using namespace Sia::Api;
|
||||
|
||||
#define TABLE_CREATE L"create table if not exists %s (%s);"
|
||||
#define UPLOAD_TABLE L"upload_table"
|
||||
#define UPLOAD_TABLE_COLUMNS L"id integer primary key autoincrement, sia_path text unique not null, cache_path text unique not null, status integer not null"
|
||||
|
||||
template <typename... Ts>
|
||||
String fmt(const String &fmt, Ts... vs)
|
||||
{
|
||||
size_t required = _sntprintf(nullptr, 0, fmt.c_str(), vs...);
|
||||
|
||||
String ret;
|
||||
ret.resize(required);
|
||||
_sntprintf(&ret[0], required, fmt.c_str(), vs...);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void CreateTableIfNotFound(SQLite::Database* database, const String& tableName, const String& columns)
|
||||
{
|
||||
String sqlCreate = fmt(TABLE_CREATE, &tableName[0], &columns[0]);
|
||||
database->exec(CW2A(sqlCreate.c_str()));
|
||||
}
|
||||
|
||||
CUploadManager::CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) :
|
||||
CAutoThread(siaCurl, siaDriveConfig),
|
||||
_uploadDatabase(siaDriveConfig->GetRenter_UploadDbFilePath(), SQLite::OPEN_CREATE | SQLite::OPEN_READWRITE)
|
||||
{
|
||||
//CreateTableIfNotFound(L"upload_table", UPLOAD_TABLE_CREATE);
|
||||
CreateTableIfNotFound(&_uploadDatabase, UPLOAD_TABLE, UPLOAD_TABLE_COLUMNS);
|
||||
StartAutoThread();
|
||||
}
|
||||
|
||||
|
@@ -12,12 +12,12 @@ using namespace Sia::Api::Dokan;
|
||||
class DokanImpl
|
||||
{
|
||||
private:
|
||||
struct OpenFileInfo
|
||||
typedef struct
|
||||
{
|
||||
String SiaPath;
|
||||
String CacheFilePath;
|
||||
bool ReadOnly;
|
||||
};
|
||||
} OpenFileInfo;
|
||||
|
||||
private:
|
||||
static std::mutex _dokanMutex;
|
||||
@@ -511,6 +511,7 @@ void CSiaDokanDrive::Mount(const wchar_t& driveLetter, const String& cacheLocati
|
||||
void CSiaDokanDrive::Unmount(const bool& clearCache)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(DokanImpl::GetMutex());
|
||||
// TODO When files are open, need to prompt and prevent shutdown?
|
||||
DokanImpl::Unmount();
|
||||
}
|
||||
|
||||
|
@@ -773,6 +773,7 @@ void CSiaDriveDlg::SetWalletUnlockPassword(const String& password)
|
||||
|
||||
bool CSiaDriveDlg::UpdateSiaInfo()
|
||||
{
|
||||
// TODO Needs to be async
|
||||
const String serverVersion = _siaApi->GetServerVersion();
|
||||
if (serverVersion.length())
|
||||
{
|
||||
@@ -806,7 +807,7 @@ bool CSiaDriveDlg::UpdateSiaInfo()
|
||||
SetRenterTotalUsed(_siaApi->GetRenter()->GetTotalUsedBytes());
|
||||
|
||||
SiaCurrency t = _siaApi->GetRenter()->GetTotalUsedBytes() ? _siaApi->GetRenter()->GetTotalUsedBytes() / (1024.0 * 1024.0 * 1024.0) : 0.0;
|
||||
auto a = (t / (allocatedFunds - unspentFunds) * allocatedFunds) * 1024.0;
|
||||
auto a = (t / (allocatedFunds - unspentFunds)) * allocatedFunds;
|
||||
SetRenterTotalAvailable(a.ToDouble());
|
||||
SetRenterTotalRemain((a-t).ToDouble());
|
||||
SetRenterTotalUploadProgress(_siaApi->GetRenter()->GetTotalUploadProgress());
|
||||
|
Reference in New Issue
Block a user