コード例 #1
0
FileType FileWatcherBaseWindows::platformFileType(std::string filename)
{
    if(FileExtensions.find(wstring_to_utf8(PathFindExtension(
                     utf8_to_wstring(filename).c_str()
                                             ))) != FileExtensions.end())
    {
        return FileExtensions.at(wstring_to_utf8(PathFindExtension(utf8_to_wstring(filename).c_str())));
    }

    else return FileType::ftFILE;
}
コード例 #2
0
ファイル: openmpt123.hpp プロジェクト: Kinglions/modizer
	virtual void write( const std::string & text ) {
		#if defined(UNICODE)
			std::wstring wtext = utf8_to_wstring( text );
			WriteConsole( handle, wtext.data(), static_cast<DWORD>( wtext.size() ), NULL, NULL );
		#else
			WriteConsole( handle, text.data(), static_cast<DWORD>( text.size() ), NULL, NULL );
		#endif
	}
コード例 #3
0
void FileWatcherBaseWindows::platformCreateDirectory(std::string dirName)
{
    DWORD dwAttrib = GetFileAttributes(utf8_to_wstring(M_config.currentlyWatchedDirectory + "/" + dirName).c_str());

    //check if directory exists, if it doesn't, create it
    if(dwAttrib == INVALID_FILE_ATTRIBUTES ||
       ~(dwAttrib & FILE_ATTRIBUTE_DIRECTORY))
    {
        BOOL success = CreateDirectory(utf8_to_wstring(M_config.currentlyWatchedDirectory + "/" + dirName).c_str(), NULL);
        switch(success)
        {
        case ERROR_ALREADY_EXISTS:
            log(FILE_WATCHER_WARN_DIR_EXIST(M_config.currentlyWatchedDirectory + "/" + dirName), _MAX_PATH + 20);
            break;
        case ERROR_PATH_NOT_FOUND:
            break;
        default:
            return;
        }
    }

    else return;
}
コード例 #4
0
ファイル: binary.cpp プロジェクト: ThorQin/libtlib
std::wstring load_string<wchar_t>(const binary& data) {
	//std::wstring result;
	bool bom;
	const char* charset = test_charset(data, bom);
	unsigned int cp = charset_to_codepage(charset);
	if (cp == 65001 && bom) { // utf-8
		return utf8_to_wstring(std::string(data.begin() + 3, data.end()));
	} else if ((cp == 1200 || cp == 1201) && bom) { // utf-16
		return charset_to_wstring(std::string(data.begin() + 2, data.end()),
				charset);
	} else
		return charset_to_wstring(std::string(data.begin(), data.end()),
				charset);

}
コード例 #5
0
bool FileWatcherBaseWindows::platformDisplayDirectory(std::string directory)
{
    char fileName[_MAX_PATH];

    //get the wide-character file-path using utf8_to_wstring
    WIN32_FIND_DATA fdFileData;
    HANDLE hFile = FindFirstFile(utf8_to_wstring(directory).c_str(), &fdFileData);

    //check if handle is ok
    if(hFile == INVALID_HANDLE_VALUE)
    {
        log(FILE_WATCHER_WARN_DIR_FAIL_DISPLAY(directory), _MAX_PATH);
        platformPrintColorS(directory + " could not be displayed properly", FILE_WATCHER_COLOR_DIR_FAIL_DISPLAY);
        std::cout << std::endl;
        return false;
    }

    else
    {
        do
        {
            //convert current filename into narrow character and change color based on FileType
            WideCharToMultiByte(CP_UTF8, 0, fdFileData.cFileName, _MAX_PATH, fileName, _MAX_PATH, NULL, NULL);

            switch(platformFileType(fileName))
            {
            case FileType::ftHEADER:
                platformPrintColorC(fileName, FILE_WATCHER_COLOR_FILE_HEADER);
                break;
            case FileType::ftFILE:
                platformPrintColorC(fileName, FILE_WATCHER_COLOR_FILE_FILE);
                break;
            case FileType::ftFOLDER:
                platformPrintColorC(fileName, FILE_WATCHER_COLOR_FILE_FOLDER);
                break;
            case FileType::ftIMPLEMENTATION:
                platformPrintColorC(fileName, FILE_WATCHER_COLOR_FILE_IMPLEMENTATION);
                break;
            }

            std::cout << std::endl;
        }while(FindNextFile(hFile, &fdFileData));
        FindClose(hFile);
    }
    return true;
}
コード例 #6
0
	mmio_stream_raii( const std::string & filename, const commandlineflags & flags_ ) : flags(flags_), mmio(NULL) {

		ZeroMemory( &waveformatex, sizeof( WAVEFORMATEX ) );
		waveformatex.cbSize = 0;
		waveformatex.wFormatTag = flags.use_float ? WAVE_FORMAT_IEEE_FLOAT : WAVE_FORMAT_PCM;
		waveformatex.nChannels = flags.channels;
		waveformatex.nSamplesPerSec = flags.samplerate;
		waveformatex.wBitsPerSample = flags.use_float ? 32 : 16;
		waveformatex.nBlockAlign = flags.channels * ( waveformatex.wBitsPerSample / 8 );
		waveformatex.nAvgBytesPerSec = waveformatex.nSamplesPerSec * waveformatex.nBlockAlign;

		#if defined(WIN32) && defined(UNICODE)
			wchar_t * tmp = wcsdup( utf8_to_wstring( filename ).c_str() );
			mmio = mmioOpen( tmp, NULL, MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_CREATE );
			free( tmp );
			tmp = 0;
		#else
			char * tmp = strdup( filename.c_str() );
			mmio = mmioOpen( tmp, NULL, MMIO_ALLOCBUF | MMIO_READWRITE | MMIO_CREATE );
			free( tmp );
			tmp = 0;
		#endif
		
		ZeroMemory( &WAVE_chunk, sizeof( MMCKINFO ) );
		WAVE_chunk.fccType = mmioFOURCC('W', 'A', 'V', 'E');
		CHECKED(mmioCreateChunk( mmio, &WAVE_chunk, MMIO_CREATERIFF ));

			ZeroMemory( &fmt__chunk, sizeof( MMCKINFO ) );
			fmt__chunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
			fmt__chunk.cksize = sizeof( WAVEFORMATEX );
			CHECKED(mmioCreateChunk( mmio, &fmt__chunk, 0 ));

				mmioWrite( mmio, (const char*)&waveformatex, sizeof( WAVEFORMATEX ) );

			CHECKED(mmioAscend( mmio, &fmt__chunk, 0 ));

			ZeroMemory( &data_chunk, sizeof( MMCKINFO ) );
			data_chunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
			data_chunk.cksize = 0;
			CHECKED(mmioCreateChunk( mmio, &data_chunk, 0 ));

				ZeroMemory( &data_info, sizeof( MMIOINFO ) );
				CHECKED(mmioGetInfo( mmio, &data_info, 0 ));

	}
コード例 #7
0
ファイル: string_convert.cpp プロジェクト: ZhHong/moon_net
std::string moon::utf8_to_string(const std::string& src)
{
	return wstring_to_string(utf8_to_wstring(src));
}