<commit_before>#include "ext-common.h"
#include "ext-utils.h"
#include "shell-ext.h"
#include "log.h"
#include "commands.h"

#include <string>

namespace utils = seafile::utils;

namespace {

bool shouldIgnorePath(const std::string& path)
{
    /* Show no menu for drive root, such as C: D: */
    if (path.size() <= 3) {
        return TRUE;
    }

    /* Ignore flash disk, network mounted drive, etc. */
    if (GetDriveType(path.substr(0, 3).c_str()) != DRIVE_FIXED) {
        return TRUE;
    }

    return FALSE;
}

const char *kMainMenuName = "Seafile";

}


STDMETHODIMP ShellExt::Initialize(LPCITEMIDLIST pIDFolder,
                                   LPDATAOBJECT pDataObj,
                                   HKEY  hRegKey)
{
    return Initialize_Wrap(pIDFolder, pDataObj, hRegKey);
}

STDMETHODIMP ShellExt::Initialize_Wrap(LPCITEMIDLIST folder,
                                        LPDATAOBJECT data,
                                        HKEY /* hRegKey */)
{
    FORMATETC format = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
    STGMEDIUM stg = {TYMED_HGLOBAL};
    HDROP drop;
    UINT count;
    HRESULT result = S_OK;
    wchar_t path_w[MAX_PATH] = {0};

    /* 'folder' param is not null only when clicking at the foler background;
       When right click on a file, it's NULL */
    if (folder) {
        if (SHGetPathFromIDListW(folder, path_w)) {
            path_ = utils::normalizedPath(utils::wStringToUtf8(path_w));
        }
    }

    /* if 'data' is NULL, then it's a background click, we have set
     * path_ to folder's name above, and the Init work is done */
    if (!data)
        return S_OK;

    /* 'data' is no null, which means we are operating on a file. The
     * following lines until the end of the function is used to extract the
     * filename of the current file. */
    if (FAILED(data->GetData(&format, &stg)))
        return E_INVALIDARG;
<commit_msg>[ext] fixed a possible memory error<commit_after>#include "ext-common.h"
#include "ext-utils.h"
#include "shell-ext.h"
#include "log.h"
#include "commands.h"

#include <string>

namespace utils = seafile::utils;

namespace {

bool shouldIgnorePath(const std::string& path)
{
    /* Show no menu for drive root, such as C: D: */
    if (path.size() <= 3) {
        return TRUE;
    }

    /* Ignore flash disk, network mounted drive, etc. */
    if (GetDriveType(path.substr(0, 3).c_str()) != DRIVE_FIXED) {
        return TRUE;
    }

    return FALSE;
}

const char *kMainMenuName = "Seafile";

}


STDMETHODIMP ShellExt::Initialize(LPCITEMIDLIST pIDFolder,
                                   LPDATAOBJECT pDataObj,
                                   HKEY  hRegKey)
{
    return Initialize_Wrap(pIDFolder, pDataObj, hRegKey);
}

STDMETHODIMP ShellExt::Initialize_Wrap(LPCITEMIDLIST folder,
                                        LPDATAOBJECT data,
                                        HKEY /* hRegKey */)
{
    FORMATETC format = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
    STGMEDIUM stg = {TYMED_HGLOBAL};
    HDROP drop;
    UINT count;
    HRESULT result = S_OK;
    wchar_t path_w[MAX_PATH] = {L'\0'};

    /* 'folder' param is not null only when clicking at the foler background;
       When right click on a file, it's NULL */
    if (folder) {
        if (SHGetPathFromIDListW(folder, path_w)) {
            path_ = utils::normalizedPath(utils::wStringToUtf8(path_w));
        }
    }

    /* if 'data' is NULL, then it's a background click, we have set
     * path_ to folder's name above, and the Init work is done */
    if (!data)
        return S_OK;

    /* 'data' is no null, which means we are operating on a file. The
     * following lines until the end of the function is used to extract the
     * filename of the current file. */
    if (FAILED(data->GetData(&format, &stg)))
        return E_INVALIDARG;

{'fraction_non_alphanumeric': 0.1068840579710145, 'fraction_numerical': 0.003105590062111801, 'mean_word_length': 2.31191088260497, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2615671', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1237, 'n_words': 369}