コード例 #1
0
 int Syncler::syncDir(const string& path){
     verbose("syncing directory %s\n",path.c_str());
     map<string,Sync::Item>& fdir=from->getItems(path);
     map<string,Sync::Item>& tdir=to->getItems(path);
     int res=0;
     for (auto it=tdir.begin(); it!=tdir.end(); ++it){
         if (fdir.count(it->first)==0 || it->second.directory!=fdir[it->first].directory){
             it->second.removed=true;
             cout << "D " << it->second.path << it->second.name << endl;
             CHECKRES(to->removeItem(it->second));
         }
     }
     vector<string> morepaths;
     for (auto it=fdir.begin(); it!=fdir.end(); ++it){
         Sync::Item& src=it->second;
         if (it->second.directory){
             morepaths.push_back(src.path+src.name);
         }
         if (tdir.count(it->first)==0 || tdir[it->first].removed){
             cout << "A " << src.path << src.name << endl;
             CHECKRES(to->addItem(from->getTransfer(src)));
             continue;
         }
         if (it->second.directory)
             continue;
         CHECKRES(syncFile(src,tdir[it->first]));
     }
     for (string& x: morepaths){
         CHECKRES(syncDir(x));
     }
     return 0;
 }
コード例 #2
0
ファイル: Wallet.cpp プロジェクト: MoeAfilal/airbitz-core
Status
Wallet::sync(bool &dirty)
{
    ABC_CHECK(syncRepo(syncDir(), syncKey_, dirty));
    if (dirty)
    {
        std::lock_guard<std::mutex> lock(mutex_);
        ABC_CHECK(loadSync());
    }

    return Status();
}
コード例 #3
0
ファイル: Wallet.cpp プロジェクト: MoeAfilal/airbitz-core
Status
Wallet::nameSet(const std::string &name)
{
    std::lock_guard<std::mutex> lock(mutex_);

    name_ = name;
    NameJson json;
    ABC_CHECK(json.nameSet(name));
    ABC_CHECK(json.save(syncDir() + WALLET_NAME_FILENAME, dataKey()));

    return Status();
}
コード例 #4
0
ファイル: Wallet.cpp プロジェクト: MoeAfilal/airbitz-core
Status
Wallet::currencySet(int currency)
{
    std::lock_guard<std::mutex> lock(mutex_);

    currency_ = currency;
    CurrencyJson currencyJson;
    ABC_CHECK(currencyJson.currencySet(currency));
    ABC_CHECK(currencyJson.save(syncDir() + WALLET_CURRENCY_FILENAME, dataKey()));

    return Status();
}
コード例 #5
0
ファイル: Wallet.cpp プロジェクト: MoeAfilal/airbitz-core
Status
Wallet::createNew(const std::string &name, int currency)
{
    // Set up the keys:
    ABC_CHECK(randomData(bitcoinKey_, BITCOIN_SEED_LENGTH));
    bitcoinKeyBackup_ = bitcoinKey_;
    ABC_CHECK(randomData(dataKey_, DATA_KEY_LENGTH));
    DataChunk syncKey;
    ABC_CHECK(randomData(syncKey, SYNC_KEY_LENGTH));
    syncKey_ = base16Encode(syncKey);

    // Create the sync directory:
    ABC_CHECK(fileEnsureDir(gContext->paths.walletsDir()));
    ABC_CHECK(fileEnsureDir(dir()));
    ABC_CHECK(fileEnsureDir(syncDir()));
    ABC_CHECK(syncMakeRepo(syncDir()));

    // Populate the sync directory:
    ABC_CHECK(currencySet(currency));
    ABC_CHECK(nameSet(name));
    ABC_CHECK(addresses.load());

    // Push the wallet to the server:
    bool dirty = false;
    ABC_CHECK(loginServerWalletCreate(account.login, syncKey_));
    ABC_CHECK(syncRepo(syncDir(), syncKey_, dirty));
    ABC_CHECK(loginServerWalletActivate(account.login, syncKey_));

    // If everything worked, add the wallet to the account:
    WalletJson json;
    ABC_CHECK(json.bitcoinKeySet(base16Encode(bitcoinKey_)));
    ABC_CHECK(json.dataKeySet(base16Encode(dataKey_)));
    ABC_CHECK(json.syncKeySet(syncKey_));
    ABC_CHECK(account.wallets.insert(id_, json));
    ABC_CHECK(account.sync(dirty));

    return Status();
}
コード例 #6
0
ファイル: Wallet.cpp プロジェクト: MoeAfilal/airbitz-core
Status
Wallet::loadSync()
{
    ABC_CHECK(fileEnsureDir(gContext->paths.walletsDir()));
    ABC_CHECK(fileEnsureDir(dir()));
    ABC_CHECK(syncEnsureRepo(syncDir(), dir() + "tmp/", syncKey_));

    // Load the currency:
    CurrencyJson currencyJson;
    currencyJson.load(syncDir() + WALLET_CURRENCY_FILENAME, dataKey());
    ABC_CHECK(currencyJson.currencyOk());
    currency_ = currencyJson.currency();

    // Load the name (failure is acceptable):
    NameJson json;
    json.load(syncDir() + WALLET_NAME_FILENAME, dataKey());
    name_ = json.name();

    // Load the databases:
    ABC_CHECK(addresses.load());
    ABC_CHECK(txs.load());

    return Status();
}
コード例 #7
0
 int Syncler::run(Sync* from,Sync* to){
     this->from=from;
     this->to=to;
     verbose("making file list...\n");
     if (from->open(flags,true))
         return 10;
     if (to->open(flags,false))
         return 11;
     int res=syncDir("");
     res+=to->close();
     res+=from->close();
     if (res){
         cerr << "sync failed: " << res << endl;
     }
     return res;
 }
コード例 #8
0
void OwncloudSyncd::syncDirs(){

    qDebug() << "Sync Dirs";

    QMapIterator<QString, QString> i(m_folderMap);
    while (i.hasNext()) {
        i.next();
        if(QDir(i.key()).exists()){
            syncDir(i.key());
            qDebug() << "Directory: " << i.key() << " - Initiate Sync";
        }else{
            qDebug() << "Directory: " << i.key() << " Doesn't exist";
        }


    }

}
コード例 #9
0
ファイル: WindowsPlatform.cpp プロジェクト: goofwear/MEGAsync
void WindowsPlatform::syncFolderAdded(QString syncPath, QString syncName, QString syncID)
{
    if (syncPath.startsWith(QString::fromAscii("\\\\?\\")))
    {
        syncPath = syncPath.mid(4);
    }

    if (!syncPath.size())
    {
        return;
    }

    QDir syncDir(syncPath);
    if (!syncDir.exists())
    {
        return;
    }

    if (!Preferences::instance()->leftPaneIconsDisabled())
    {
        addSyncToLeftPane(syncPath, syncName, syncID);
    }

    DWORD dwVersion = GetVersion();
    DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
    int iconIndex = (dwMajorVersion<6) ? 2 : 3;

    QString infoTip = QCoreApplication::translate("WindowsPlatform", "MEGA synced folder");
    SHFOLDERCUSTOMSETTINGS fcs = {0};
    fcs.dwSize = sizeof(SHFOLDERCUSTOMSETTINGS);
    fcs.dwMask = FCSM_ICONFILE | FCSM_INFOTIP;
    fcs.pszIconFile = (LPWSTR)MegaApplication::applicationFilePath().utf16();
    fcs.iIconIndex = iconIndex;
    fcs.pszInfoTip = (LPWSTR)infoTip.utf16();
    SHGetSetFolderCustomSettings(&fcs, (LPCWSTR)syncPath.utf16(), FCS_FORCEWRITE);

    WCHAR path[MAX_PATH];
    HRESULT res = SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path);
    if (res != S_OK)
    {
        return;
    }

    QString linksPath = QString::fromWCharArray(path);
    linksPath += QString::fromAscii("\\Links");
    QFileInfo info(linksPath);
    if (!info.isDir())
    {
        return;
    }

    QString linkPath = linksPath + QString::fromAscii("\\") + syncName + QString::fromAscii(".lnk");
    if (QFile(linkPath).exists())
    {
        return;
    }

    WCHAR wDescription[]=L"MEGAsync synchronized folder";
    linkPath = QDir::toNativeSeparators(linkPath);
    WCHAR *wLinkPath = (WCHAR *)linkPath.utf16();

    syncPath = QDir::toNativeSeparators(syncPath);
    WCHAR *wSyncPath = (WCHAR *)syncPath.utf16();

    QString exec = MegaApplication::applicationFilePath();
    exec = QDir::toNativeSeparators(exec);
    WCHAR *wExecPath = (WCHAR *)exec.utf16();
    res = CreateLink(wSyncPath, wLinkPath, wDescription, wExecPath);

    SHChangeNotify(SHCNE_CREATE, SHCNF_PATH | SHCNF_FLUSHNOWAIT, wLinkPath, NULL);

    WCHAR *wLinksPath = (WCHAR *)linksPath.utf16();
    SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH | SHCNF_FLUSHNOWAIT, wLinksPath, NULL);
    SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, syncPath.utf16(), NULL);
}
コード例 #10
0
ファイル: Wallet.hpp プロジェクト: TSchnaars/airbitz-core
 std::string txDir() const       { return syncDir() + "Transactions/"; }