I would streamline the logic of StoreInitialize like this, removing
goto and half of ifdefs. A goto for name selection is overkill :).

(I didn't compile this though)

void FileStore::StoreInitialize(const NameValuePairs &parameters)
{
        m_waiting = false;
        m_stream = NULL;
        m_file.release();

        const char* narrowName = NULL;
        const wchar_t* wideName = NULL;
        bool useWideName = false;

        if(parameters.GetValue(Name::InputFileName(), narrowName))
                useWideName = false;
        #if defined(CRYPTOPP_UNIX_AVAILABLE) || _MSC_VER >= 1400
        else if (parameters.GetValue(Name::InputFileNameWide(), wideName))
                useWideName = true;
        #endif
        else
        {
                parameters.GetValue(Name::InputStreamPointer(), m_stream);
                return;
        }

        ios::openmode binary = parameters.GetValueWithDefault
(Name::InputBinaryMode(), true) ? ios::binary : ios::openmode(0);
        m_file.reset(new std::ifstream);

        if(useWideName)
        {
        #if _MSC_VER >= 1400
                m_file->open(wideName, ios::in | binary);
        #else
                m_file->open(StringNarrow(wideName).c_str(), ios::in | binary);
        #endif
        }
        else
                m_file->open(narrowName, ios::in | binary);

        if (!*m_file)
                throw OpenErr(fileName);
        m_stream = m_file.get();
}

On Jul 10, 7:51 pm, "Wei Dai" <[email protected]> wrote:
> Eugene Zolenko wrote:
> > On windows you can use non-standard extention to fstreams -- they can
> > be created from FILE handles, and FILEs can be created using _wfopen.
> > And FileSink/Source can be created using fstreams.
>
> > std::wstring path = L"D:\bla.txt";
> > FILE* handle = _wfopen(path, L"rb");
> > std::ifstream file(handle);
> > CryptoPP::FileSource(file, ...);
>
> It turns out that ifstream::open in MSVC 2005 and later can handle a Unicode
> filename directly.
>
> > On Linux you will have to convert you std::wstring into UTF8 encoded
> > std::string first. (Using your favorite UTF8 conversion libraries :)).
>
> wcstombs() can be used for this, and it seems to be a standard Unix
> function.
>
> I've checked in changes to enable FileSource, FileSink, and FileStore to
> handle Unicode filenames on Unix and MSVC 2005 and later using the above
> methods. Please take a look 
> athttp://cryptopp.svn.sourceforge.net/viewvc/cryptopp?view=rev&revision...if
> you'd like to review the code.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to