Exemplo n.º 1
0
bool GetFileStatusCommand::parseResponse(const std::string& raw_resp,
                                         RepoInfo::Status *status)
{
    // seaf_ext_log ("raw_resp is %s\n", raw_resp.c_str());

    if (raw_resp == "syncing") {
        *status = RepoInfo::Syncing;
    } else if (raw_resp == "synced") {
        *status = RepoInfo::Normal;
    } else if (raw_resp == "error") {
        *status = RepoInfo::Error;
    } else if (raw_resp == "paused") {
        *status = RepoInfo::Paused;
    } else if (raw_resp == "readonly") {
        *status = RepoInfo::ReadOnly;
    } else if (raw_resp == "locked") {
        *status = RepoInfo::LockedByOthers;
    } else if (raw_resp == "locked_by_me") {
        *status = RepoInfo::LockedByMe;
    } else if (raw_resp == "ignored") {
        *status = RepoInfo::NoStatus;
    } else {
        *status = RepoInfo::NoStatus;

        seaf_ext_log ("[GetFileStatusCommand] status for %s is %s, raw_resp is %s\n",
                      path_in_repo_.c_str(),
                      seafile::toString(*status).c_str(), raw_resp.c_str());
    }

    return true;
}
Exemplo n.º 2
0
bool
checkLastError()
{
    DWORD last_error = GetLastError();
    if (last_error != ERROR_IO_PENDING && last_error != ERROR_SUCCESS) {
        if (last_error == ERROR_BROKEN_PIPE || last_error == ERROR_NO_DATA
            || last_error == ERROR_PIPE_NOT_CONNECTED) {
            seaf_ext_log ("connection broken with error: %s",
                          formatErrorMessage().c_str());
        } else {
            seaf_ext_log ("failed to communicate with seafile client: %s",
                          formatErrorMessage().c_str());
        }
        return false;
    }
    return true;
}
Exemplo n.º 3
0
bool
doPipeWait (HANDLE pipe, OVERLAPPED *ol, DWORD len)
{
    DWORD bytes_rw, result;
    result = WaitForSingleObject (ol->hEvent, kPipeWaitTimeMSec);
    if (result == WAIT_OBJECT_0) {
        if (!GetOverlappedResult(pipe, ol, &bytes_rw, false)
            || bytes_rw != len) {
            seaf_ext_log ("async read failed: %s",
                            formatErrorMessage().c_str());
            return false;
        }
    } else if (result == WAIT_TIMEOUT) {
        seaf_ext_log ("connection timeout");
        return false;

    } else {
        seaf_ext_log ("failed to communicate with seafil client: %s",
                      formatErrorMessage().c_str());
        return false;
    }

    return true;
}
Exemplo n.º 4
0
// This is called when you invoke a command on the menu
STDMETHODIMP ShellExt::InvokeCommand_Wrap(LPCMINVOKECOMMANDINFO info)
{
    // see http://stackoverflow.com/questions/11443282/winapi-shell-extension-overriding-windows-command
    if (HIWORD(info->lpVerb))
        return E_INVALIDARG;

    if (path_.empty()) {
        return E_INVALIDARG;
    }

    UINT id = LOWORD(info->lpVerb);
    if (id == 0)
        return S_OK;

    id--;
    if (id > active_menu_items_.size() - 1) {
        seaf_ext_log ("invalid menu id %u", id);
        return S_FALSE;
    }

    MenuOp op = active_menu_items_[id];

    if (op == GetShareLink) {
        seafile::GetShareLinkCommand cmd(path_);
        cmd.send();
    } else if (op == GetInternalLink) {
        seafile::GetInternalLinkCommand cmd(path_);
        cmd.send();
    } else if (op == LockFile) {
        seafile::LockFileCommand cmd(path_);
        cmd.send();
    } else if (op == UnlockFile) {
        seafile::UnlockFileCommand cmd(path_);
        cmd.send();
    } else if (op == ShareToUser) {
        seafile::PrivateShareCommand cmd(path_, false);
        cmd.send();
    } else if (op == ShareToGroup) {
        seafile::PrivateShareCommand cmd(path_, true);
        cmd.send();
    } else if (op == ShowHistory) {
        seafile::ShowHistoryCommand cmd(path_);
        cmd.send();
    }

    return S_OK;
}
Exemplo n.º 5
0
bool ListReposCommand::parseResponse(const std::string& raw_resp,
                                     RepoInfoList *infos)
{
    std::vector<std::string> lines = utils::split(raw_resp, '\n');
    if (lines.empty()) {
        return true;
    }
    for (size_t i = 0; i < lines.size(); i++) {
        std::string line = lines[i];
        std::vector<std::string> parts = utils::split(line, '\t');
        if (parts.size() != 5) {
            continue;
        }
        std::string repo_id, repo_name, worktree, status;
        RepoInfo::Status st;
        bool support_file_lock;

        repo_id = parts[0];
        repo_name = parts[1];
        worktree = utils::normalizedPath(parts[2]);
        status = parts[3];
        support_file_lock = parts[4] == "file-lock-supported";
        if (status == "paused") {
            st = RepoInfo::Paused;
        } else if (status == "syncing") {
            st = RepoInfo::Syncing;
        } else if (status == "error") {
            st = RepoInfo::Error;
        } else if (status == "normal") {
            st = RepoInfo::Normal;
        } else {
            // impossible
            seaf_ext_log ("bad repo status \"%s\"", status.c_str());
            continue;
        }
        // seaf_ext_log ("status for %s is \"%s\"", repo_name.c_str(), status.c_str());
        infos->push_back(RepoInfo(repo_id, repo_name, worktree, st, support_file_lock));
    }

    reposInfoTimestamp = utils::currentMSecsSinceEpoch();
    return true;

}
Exemplo n.º 6
0
bool doInThread(LPTHREAD_START_ROUTINE func, void *data)
{
    DWORD tid = 0;
    HANDLE thread = CreateThread
        (NULL,                  /* security attr */
         0,                     /* stack size, 0 for default */
         func,                  /* start address */
         (void *)data,          /* param*/
         0,                     /* creation flags */
         &tid);                 /* thread ID */

    if (!thread) {
        seaf_ext_log ("failed to create thread");
        return false;
    }

    CloseHandle(thread);
    return true;
}
Exemplo n.º 7
0
STDMETHODIMP ShellExt::IsMemberOf(LPCWSTR path_w, DWORD attr)
{
    if (!seafile::utils::isShellExtEnabled()) {
        return S_FALSE;
    }

    std::string path = utils::wStringToStdString(path_w);

    if (!path.size()) {
        seaf_ext_log ("convert to char failed");
        return S_FALSE;
    }

    // seaf_ext_log ("IsMemberOf called for %s!", path.c_str());

    /* If length of path is shorter than 3, it should be a drive path,
     * such as C:\ , which should not be a repo folder ; And the
     * current folder being displayed must be "My Computer". If we
     * don't return quickly, it will lag the display.
     */
    if (path.size() <= 3) {
        return S_FALSE;
    }

    if (access(path.c_str(), F_OK) < 0 ||
        !(GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY)) {
        return S_FALSE;
    }

    seafile::RepoInfo info = getRepoInfoByPath(utils::localeToUtf8(path));
    if (info.isValid() && info.status == status_) {
        // seaf_ext_log ("[ICON] %d Set for %s", (int)status_, path.c_str());
        return S_OK;
    }
    return S_FALSE;
}