New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf8 characters on download folder #91

Closed
mbsanchez opened this Issue Oct 14, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@mbsanchez

mbsanchez commented Oct 14, 2015

I have an issue with special characters (non ANSI characters) on download folders (DestDir and InterDir). To reproduce this issue I open The command prompt on Windows "cmd", and then I run next commands on nzbget app folder:

chcp 65001
nzbget.exe -s -c "C:\ProgramData\NZBGet\nzbget.conf" -o MainDir="C:\ïóöüjjsn" -o DestDir="C:\ïóöüjjsn\completed" -o InterDir="C:\ïóöüjjsn\incomplete" -o NzbDir="C:\ïóöüjjsn\nzb" -o QueueDir="C:\ProgramData\NZBGet\queue" -o TempDir="C:\ProgramData\NZBGet\tmp" -o WebDir="C:\ProgramData\NZBGet\webui" -o ScriptDir="C:\ProgramData\NZBGet\scripts" -o LockFile="C:\ProgramData\NZBGet\lock" -o LogFile="C:\ProgramData\NZBGet\nzbget.log" -o Server1.Host="myusenetserver" -o Server1.Port="563" -o Server1.Username="myusername" -o Server1.Password="mypassword" -o Server1.Encryption="yes" -o Server1.Connections="2" -o ControlIP="127.0.0.1" -o ControlPort="6790" -o ControlUsername="nzbget" -o ControlPassword="test" -o ConfigTemplate="C:\ProgramData\NZBGet\nzbget.conf"

I have nzbget.conf, and webui on the folder "C:\ProgramData\NZBGet".

Well, when nzbget executes it creates the folders: "C:\ïóöüjjsn", "C:\ïóöüjjsn\incomplete", "C:\ïóöüjjsn\nzb", "C:\ïóöüjjsn\completed" with the correct name using utf8 encoding, but when it starts downloading a nzb file, nzbget creates the folder "C:____jjsn\intermediate" to store the intermediate files, then, when the files has been completely downloaded, nzbget create the folder "C:____jjsn\completed\NZB File Name" to save the final files.

It's clear that nzbget changes any non ANSI character on path by underscore (_), but i don't know why!. I have reviewed the code at: https://github.com/nzbget/nzbget/blob/develop/daemon/queue/DownloadInfo.cpp#L519 and I have noticed that on line 534 this function is called: WebUtil::Utf8ToAnsi(szDestDir, 1024); This function changes all non ANSI characters on path by underscore only on Windows, I have commented this lines of code (also the lines 575-577) and I have rebuilt nzbget, then, I have run the command above, and all goes well (files are stored on: "C:\ïóöüjjsn\incomplete" and "C:\ïóöüjjsn\completed"), but I don't know what issues can be caused by commenting this lines.

I think that probably you will call Utf8ToAnsi over the filename and not in the whole path, something like this:

void NZBInfo::BuildDestDirName()
{
    char szDestDir[1024];

    if (Util::EmptyStr(g_pOptions->GetInterDir()))
    {
        BuildFinalDirName(szDestDir, 1024);
    }
    else
    {
        char szFileName[256];
        snprintf(szFileName, 256, "%s", GetName());
        szFileName[256-1]= '\0';
#ifdef WIN32
        WebUtil::Utf8ToAnsi(szFileName, 256);
#endif
        snprintf(szDestDir, 1024, "%s%s.#%i", g_pOptions->GetInterDir(), szFileName, GetID());
        szDestDir[1024-1] = '\0';
    }

    SetDestDir(szDestDir);
}

void NZBInfo::BuildFinalDirName(char* szFinalDirBuf, int iBufSize)
{
    char szBuffer[1024];
    bool bUseCategory = m_szCategory && m_szCategory[0] != '\0';

    snprintf(szFinalDirBuf, iBufSize, "%s", g_pOptions->GetDestDir());
    szFinalDirBuf[iBufSize-1] = '\0';

    if (bUseCategory)
    {
        Options::Category *pCategory = g_pOptions->FindCategory(m_szCategory, false);
        if (pCategory && pCategory->GetDestDir() && pCategory->GetDestDir()[0] != '\0')
        {
            snprintf(szFinalDirBuf, iBufSize, "%s", pCategory->GetDestDir());
            szFinalDirBuf[iBufSize-1] = '\0';
            bUseCategory = false;
        }
    }

    if (g_pOptions->GetAppendCategoryDir() && bUseCategory)
    {
        char szCategoryDir[1024];
        strncpy(szCategoryDir, m_szCategory, 1024);
        szCategoryDir[1024 - 1] = '\0';
        Util::MakeValidFilename(szCategoryDir, '_', true);

        snprintf(szBuffer, 1024, "%s%s%c", szFinalDirBuf, szCategoryDir, PATH_SEPARATOR);
        szBuffer[1024-1] = '\0';
        strncpy(szFinalDirBuf, szBuffer, iBufSize);
    }

    char szFileName[256];
    snprintf(szFileName, 256, "%s", GetName());
    szFileName[256-1]= '\0';
#ifdef WIN32
    WebUtil::Utf8ToAnsi(szFileName, 256);
#endif
    snprintf(szBuffer, 1024, "%s%s", szFinalDirBuf, szFileName);
    szBuffer[1024-1] = '\0';
    strncpy(szFinalDirBuf, szBuffer, iBufSize);
}

Do you know another way to fix this issue? it's important because for many user the download folder is inner to her home folder, but home folder can be C:\Users\ësmary, then the download folder will be C:\Users\ësmary\downloads, that causes that nzbget creates the folder: C:\Users_smary\downloads, what is an incorrect path.

@hugbug hugbug added the improvement label Oct 20, 2015

@hugbug hugbug referenced this issue Dec 28, 2015

Closed

Unicode and extra long file paths on Windows #136

7 of 7 tasks complete
@hugbug

This comment has been minimized.

Show comment
Hide comment
@hugbug

hugbug Dec 29, 2015

Member

Fixed in #136 (for v17.0).

Member

hugbug commented Dec 29, 2015

Fixed in #136 (for v17.0).

@hugbug hugbug closed this Dec 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment