1
0

Upload manager changes

This commit is contained in:
Scott E. Graves
2017-02-20 15:38:18 -06:00
parent 0c90d3d116
commit 5db3f618bc
4 changed files with 28 additions and 5 deletions

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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());