void CCsvFileWriter::OnCache(CGeoCache& Cache)
{
	AW_CONVERSION;

	fprintf(
		m_fd, 
		"\"%s :: %s\",\"%4.10f\",\"%4.10f\"\r\n",
		w2a((TCHAR*) Cache.m_Shortname.c_str()),
		w2a((TCHAR*) Cache.m_GsCacheName.c_str()),
		Cache.m_Lat,
		Cache.m_Long);
}
std::string strconv::w2utf8(std::wstring str)
{
#ifdef _WIN32

	// Calculate required buffer size
	int count = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, NULL, 0, NULL, NULL);
    if(count==0)
    {
       return "";
    }

    // Convert UNICODE->UTF8
    char* buf = new char[count];
	int result = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), -1, (LPSTR)buf, count, NULL, NULL);
    if(result==0)
    {
        delete [] buf;
        return "";
    }

	std::string utf8(buf);
	delete [] buf;
	return utf8;

#else
	// On Linux do widechar->multibyte conversion.
	return w2a(str);
#endif
}
Beispiel #3
0
char *utf2a(const char *utfs)
{
	wchar_t *ws = utf2w(utfs);
	char *ret = w2a(ws);
	mir_free(ws);
	return ret;
}
Beispiel #4
0
        tstring utf82t(LPCSTR arg, size_t length)
        {
#ifdef _UNICODE
            return utf82w(arg, length);
#else
            std::wstring result = utf82w(arg, length);
            return w2a(result.c_str(), result.length());
#endif
        }
Beispiel #5
0
bool loadModules()
{
    loadEmbeddedModules(L);

    ChangeDir cd;
    if (!cd.changeDir(L"modules"))
    {
        lua_register(L, "require", require_stub);
        return false;
    }

    tstring path(cd.getCurrentDir());
    path.append(L"\\modules\\?.dll");
    luaopen_package(L);
    lua_pushstring(L, "path");
    lua_pushstring(L, "");
    lua_settable(L, -3);
    lua_pushstring(L, "cpath");
    lua_pushstring(L, TW2A(path.c_str()));
    lua_settable(L, -3);
    lua_setglobal(L, "package");
    lua_pop(L, 1);

    std::vector<tstring> files;
    {
        WIN32_FIND_DATA fd;
        memset(&fd, 0, sizeof(WIN32_FIND_DATA));
        HANDLE file = FindFirstFile(L"*.*", &fd);
        if (file != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
                {
                    if (Module::isModule(fd.cFileName))
                        files.push_back(fd.cFileName);
                }
            } while (::FindNextFile(file, &fd));
            ::FindClose(file);
        }
    }

    for (int j = 0, je = files.size(); j < je; ++j)
    {
        TW2A w2a(files[j].c_str());
        if (luaL_dofile(L, w2a))
        {
            tstring error(L"Ошибка при загрузке модуля: '");
            error.append(files[j]);
            error.append(L"' - ");
            error.append(luaT_towstring(L, -1));
            pluginOut(error.c_str());
        }
    }
    return true;
}
Beispiel #6
0
CStringA CSySkin::W2CStringA(CString in_Str)
{
	CStringA strResult;
#ifdef _UNICODE
	CW2A w2a(in_Str);
	PCHAR pszResult = (LPSTR)w2a;
	strResult.Format("%s", pszResult);
#else
	strResult = in_Str;
#endif
	return strResult;
}
Beispiel #7
0
runner::env_vars_list_t runner::read_environment(const WCHAR* source) const
{
    env_vars_list_t vars;

    for (WCHAR* env = (WCHAR*)source; *env != '\0';)
    {
        std::string envStr(w2a((const WCHAR*)env));

        int pos = envStr.find("=");

        vars.push_back(make_pair(envStr.substr(0, pos), envStr.substr(pos + 1)));

        env += envStr.length() + 1;
    }

    return vars;
}
Beispiel #8
0
void runner::copy_environment(TCHAR* dest, const WCHAR* source) const {
    int written = 0;

    for (WCHAR* env = (WCHAR*)source; *env != '\0';)
    {
        TCHAR* ansi = w2a((const WCHAR*)env);

        strcpy(dest, ansi);

        int bytes = strlen(ansi) + 1;

        written += bytes;
        env += bytes;
        dest += bytes;
    }

    *dest = '\0';
}
Beispiel #9
0
BOOL CMainFrame::InitRibbonTheme()
{
    std::wstring themeName(getUIOptions()->GetString(L"themeName", L"OFFICE2010SILVER.INI"));
    std::wstring themeDll(getUIOptions()->GetString(L"themeDll", L"Office2010.dll"));

    getUIOptions()->SetString(L"themeDll", themeDll.c_str());
    getUIOptions()->SetString(L"themeName", themeName.c_str());

    themeDll = getTranslationsPath((L"../" + themeDll).c_str());
    BOOL ret = XTPResourceImages()->SetHandle(themeDll.c_str(), themeName.c_str());

    if (!ret)
    {
        std::wstring dllfile(getTranslationsPath(L"../Office2007.dll"));
        ret = XTPResourceImages()->SetHandle(dllfile.c_str(), L"OFFICE2007BLUE.INI");
        if (ret)
        {
            getUIOptions()->SetString(L"themeDll", L"Office2007.dll");
            getUIOptions()->SetString(L"themeName", L"OFFICE2007BLUE.INI");
        }
    }

    if (ret)
    {
        XTPPaintManager()->SetTheme(xtpThemeRibbon);
        m_cmdbars->SetTheme(xtpThemeRibbon);
    }
    else
    {
        CString msg;
        msg.Format(L"Need Office2010.dll or Office2007.dll in the translations folder: %s.\n", getTranslationsPath(L"..").c_str());
        ASSERT_MESSAGE(0, w2a(msg).c_str());
    }

    return ret;
}
HRESULT CVBoxMachine::Open()
{
	// Check not already open
	ASSERT(!IsOpen());

	// Create VirtualBox object
	log("Creating VirtualBox\n");
	ClearComErrorInfo();
	HRESULT hr=m_spVirtualBox.CoCreateInstance(__uuidof(VirtualBox));
	if (FAILED(hr))
	{
		Close();
		return SetError(Format(L"Failed to create VirtualBox COM server - %s", vboxFormatError(hr)));
	}

	// Get machine ID
	log("Finding machine\n");
	ClearComErrorInfo();
	hr=m_spVirtualBox->FindMachine(CComBSTR(m_strMachineName), &m_spMachine);
	if (FAILED(hr) || m_spMachine==NULL)
	{
		Close();
		return SetError(Format(L"Machine \"%s\" not found - %s", m_strMachineName, vboxFormatError(hr)));
	}
	m_spMachine->get_Id(&m_bstrMachineID);

	// Open log file
	CComBSTR bstrLogFolder;
	m_spMachine->get_LogFolder(&bstrLogFolder);
	log_open(w2a(SimplePathAppend(bstrLogFolder, L"VBoxHeadlessTray.log")));

	// Connect listener for IVirtualBoxCallback
	log("Registering virtualbox callback\n");
	CComPtr<IEventSource> spEventSource;
	m_spVirtualBox->get_EventSource(&spEventSource);


	SAFEARRAYBOUND bound;
	bound.lLbound=0;
	bound.cElements=1;
	SAFEARRAY* interesting = SafeArrayCreate(VT_I4, 1, &bound);
	int* pinteresting;
	SafeArrayAccessData(interesting, (void**)&pinteresting);
	pinteresting[0]=VBoxEventType_OnMachineStateChanged;
	SafeArrayUnaccessData(interesting);
	spEventSource->RegisterListener(&m_EventListener, interesting, VARIANT_TRUE);
	SafeArrayDestroy(interesting);

	// Since VBox 4.1 seems to fail to send machine state events, lets just poll the machine every 5 seconds
	// If we get a real machine state event, we'll kill this, assuming it's working
	// The VBoxHeadlessTray machine window also calls OnMachineStateChanged from it's tray icon
	// update timer.... so when things are transitioning the state should update fairly quickly.
	m_hPollTimer = SetCallbackTimer(1000, 0, OnPollMachineState, (LPARAM)this);

	m_bCallbackRegistered=true;

	m_spMachine->get_State(&m_State);


	return S_OK;
}
Beispiel #11
0
PSgmlEl CSgmlEl::search(const wchar_t* TagName) {
  return search(w2a(TagName).c_str());
}
Beispiel #12
0
WideString const CSgmlEl::GetChrParam(const wchar_t* par) const {
  char const * val = GetChrParam(w2a(par).c_str());
  return a2w(val);
}
Beispiel #13
0
bool  CSgmlEl::isNamed(WideString const &name) const {
  return strcmp(w2a(name).c_str(), this->name) == 0;
}
Beispiel #14
0
// Open a file
result_t CFile::Open(const CAnyString& pszFileName, uint32_t flags)
{
	Close();

	// If create or open mode specified, select depending on file existance
	if ((flags & ffCreate) && (flags & ffOpen))
	{
		if (DoesFileExist(pszFileName))
			flags &= ~ffCreate;
		else
			flags &= ~ffOpen;
	}

	// Work out fopen flags
	const wchar_t* pszFlags=NULL;
	switch (flags & 0x000F)
	{
		case ffWrite|ffCreate:
			pszFlags=L"wb";
			break;

		case ffRead|ffOpen:
			pszFlags=L"rb";
			break;

		case ffRead|ffWrite|ffCreate:
			pszFlags=L"wb+";
			break;

		case ffRead|ffWrite|ffOpen:
			pszFlags=L"rb+";
			break;

		default:
			return e_invalidarg;
	}

#ifdef _MSC_VER

	// Work out sharing flags
	int shareflag=_SH_DENYRW;
	switch (flags & (ffShareRead|ffShareWrite))
	{
		case ffShareRead|ffShareWrite:
			shareflag=_SH_DENYNO;
			break;

		case ffShareRead:
			shareflag=_SH_DENYWR;
			break;

		case ffShareWrite:
			shareflag=_SH_DENYRD;
			break;
	}

	// Open file
	m_pFile=_wfsopen(pszFileName, pszFlags, shareflag);
	if (!m_pFile)
		return ResultFromErrno(errno);

#else

	m_pFile=fopen64(pszFileName, w2a(pszFlags));
	if (!m_pFile)
		return ResultFromErrno(errno);

#endif

	// Append?
	if ((flags & ffAppend) && (flags & ffOpen))
	{
		fseek(m_pFile, 0, SEEK_END);
	}

	// Done
	return s_ok;
}
Beispiel #15
0
bool t2a(const TCHAR *ts, char *buff, int bufflen) 
{
	return w2a(ts, buff, bufflen);
}
Beispiel #16
0
HANDLE WINAPI OpenW(const struct OpenInfo *Info)
{
    const int CUR_DIR_SIZE = 100000;
    char* filename = 0;

    switch( Info->OpenFrom )
    {
    case OPEN_COMMANDLINE:
        {
            OpenCommandLineInfo* cinfo = (OpenCommandLineInfo*)Info->Data;

            const wchar_t* cmdline = cinfo->CommandLine;
            if( !cmdline )
                return INVALID_HANDLE_VALUE;

            while( *cmdline && *cmdline <= ' ' )
                cmdline++;

            if( *cmdline )
                filename = w2a( cmdline );
            else
                return 0;
            break;
        }
    case OPEN_PLUGINSMENU:
        {
            FarGetPluginPanelItem pinfo;
            PluginPanelItem* pitem = (PluginPanelItem*)malloc(CUR_DIR_SIZE);
            ZeroMemory(&pinfo, sizeof(pinfo));
            ZeroMemory(pitem, CUR_DIR_SIZE);
            pinfo.StructSize = sizeof(pinfo);
            pinfo.Size = CUR_DIR_SIZE;
            pinfo.Item = pitem;

            if(InfoW.PanelControl( PANEL_ACTIVE, FCTL_GETCURRENTPANELITEM, 0, &pinfo ))
            {
                filename = w2a( pinfo.Item->FileName );
                free(pitem);
            }
            else
            {
                free(pitem);
                return 0;
            }
            break;
        }
    default:
        return 0;
    }
    
    if( !filename )
        return 0;

    wchar_t comspec[MAX_PATH * 2];
    if( !GetEnvironmentVariableW( L"COMSPEC", comspec, sizeofa( comspec ) ) )
        lstrcpyW( comspec, L"cmd.exe" );

    char pipename[100];
    wsprintf( pipename, "\\\\.\\pipe\\FarCall%ul", GetCurrentProcessId() );

    char* batchstr = (char*)malloc( 10000 );
    wsprintf( batchstr, batch, filename, ModuleName, pipename );

    // obtaining temp file name
    wchar_t tmp[MAX_PATH * 10];
    GetTempPathW( sizeofa( tmp ), tmp );
    GetTempFileNameW( tmp, L"", 0, tmp );
    DeleteFileW( tmp );

    lstrcatW( tmp, L".bat" );

    HANDLE file = CreateFileW( tmp, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0 );
    if( !file || file == INVALID_HANDLE_VALUE )
    {
        DeleteFileW( tmp );
        free( filename );
        free( batchstr );
        return INVALID_HANDLE_VALUE;
    }

    DWORD written;
    WriteFile( file, batchstr, lstrlen( batchstr ), &written, 0 );
    CloseHandle( file );

    wchar_t cmd[MAX_PATH * 10] = L"\"";
    lstrcatW( lstrcatW( lstrcatW( lstrcatW( cmd, comspec ), L"\" /c \"" ), tmp ), L"\"");

    STARTUPINFOW sinfo;
    ZeroMemory( &sinfo, sizeof( sinfo ) );
    sinfo.cb = sizeof( sinfo );

    PROCESS_INFORMATION pinfo;

    Handle np( CreateNamedPipe( pipename, PIPE_ACCESS_DUPLEX, PIPE_WAIT,
                                PIPE_UNLIMITED_INSTANCES, 100, 100, 0, 0 ) );

    connected = false;

    DWORD id;
    Handle thread( CreateThread( 0, 0, ListenEnv, np, 0, &id ) );
    
    while( !connected )
        Sleep( 100 );
    
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &csbi );
    
#ifndef LIGHTGRAY
#define LIGHTGRAY 7
#endif

    wchar_t Blank[1024];
    FSFW.sprintf(Blank,L"%*s",csbi.dwSize.X,L"");
    FarColor fc = {FCF_NONE, LIGHTGRAY, 0, 0};
    for (int Y=0;Y<csbi.dwSize.Y;Y++)
        InfoW.Text(0,Y,&fc,Blank);
    InfoW.Text(0,0,0,NULL);
    
    COORD C;
    C.X=0;
    C.Y=csbi.dwCursorPosition.Y;
    SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), C );

    wchar_t* curr_dir = (wchar_t*)malloc(CUR_DIR_SIZE);
    
    FSFW.GetCurrentDirectory(CUR_DIR_SIZE, curr_dir);

    if( np && CreateProcessW( NULL, cmd, 0, 0, TRUE, 0, 0, curr_dir[0] ? curr_dir : 0, &sinfo, &pinfo ) )
    {

        HANDLE ar[] = {pinfo.hProcess, np};

        WaitForMultipleObjects( 2, ar, TRUE, INFINITE );
        CloseHandle(pinfo.hProcess);
        CloseHandle(pinfo.hThread);
        SMALL_RECT src;
        COORD dest;
        CHAR_INFO fill;
        src.Left=0;
        src.Top=2;
        src.Right=csbi.dwSize.X;
        src.Bottom=csbi.dwSize.Y;
        dest.X=dest.Y=0;
        fill.Char.AsciiChar=' ';
        fill.Attributes=7;
        ScrollConsoleScreenBuffer( GetStdHandle( STD_OUTPUT_HANDLE ), &src, NULL, dest, &fill);

        InfoW.AdvControl(0, ACTL_REDRAWALL, 0, 0);
    }
    else
        Handle onp( CreateFile( pipename, GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0 ) );

    
    free( filename );
    free( batchstr );
    free( curr_dir );
    DeleteFileW( tmp );
    
    return 0;
}
Beispiel #17
0
bool
EnsureAvailableTextEncoding(wxFontEncoding *enc, wxString *text, bool mayAskUser)
{
   CHECK( enc, false, _T("CheckEncodingAvailability: NULL encoding") );

   if ( !wxFontMapper::Get()->IsEncodingAvailable(*enc) )
   {
      // try to find another encoding
      wxFontEncoding encAlt;
      if ( wxFontMapper::Get()->
            GetAltForEncoding(*enc, &encAlt, wxEmptyString, mayAskUser) )
      {
         // translate the text (if any) to the equivalent encoding
         if ( text && !text->empty() )
         {
#if wxUSE_WCHAR_T
            // try converting via Unicode
            wxCSConv a2w(*enc);
            wxWCharBuffer wbuf(a2w.cMB2WC(text->c_str()));
            if ( *wbuf )
            {
               wxString textConv;

               // special case of UTF-8 which is used all the time under wxGTK
               if ( encAlt == wxFONTENCODING_UTF8 )
               {
                  textConv = wxConvUTF8.cWC2MB(wbuf);
               }
               else // all the other encodings, use generic converter
               {
                  wxCSConv w2a(encAlt);
                  textConv = w2a.cWC2MB(wbuf);
               }

               if ( !textConv.empty() )
               {
                  *text = textConv;
                  return true;
               }
               //else: fall back to wxEncodingConverter
            }
            //else: conversion to Unicode failed
#endif // wxUSE_WCHAR_T

            wxEncodingConverter conv;
            if ( !conv.Init(*enc, encAlt) )
            {
               // failed to convert the text
               return false;
            }

            *text = conv.Convert(*text);
         }
         //else: just return the encoding

         *enc = encAlt;
      }
      else // no equivalent encoding
      {
         return false;
      }
   }

   // we have either the requested encoding or an equivalent one
   return true;
}
Beispiel #18
0
std::string strconv::utf82a(std::string str)
{
	return w2a(utf82w(str));
}
Beispiel #19
0
char *t2a(const TCHAR *ts)
{
	return w2a(ts);
}
// Called for each cache to write out the corresponding waypoint to be used by the GPS
void CPocketStreetPushPinsWriter::OnCache(CGeoCache& Cache)
{
#ifndef M_PI
	#define M_PI 3.14159265358979323846
#endif

	AW_CONVERSION;

	char tbuf[64];
	int i;

	/* convert lat/long back to radians */
	double lat = (Cache.m_Lat * M_PI) / 180.0;
    double lon = (Cache.m_Long * M_PI) / 180.0;
        
	m_PIndex++;

	le_write16(tbuf, m_PIndex);
        
	/* 2 bytes - pin index */
    fwrite(tbuf, 1, 2, m_fd);
        
    /* 2 bytes - null bytes */
    memset(tbuf, '\0', sizeof(tbuf));
    fwrite(tbuf, 1, 2, m_fd);
        
	/* set the grid byte */
	char c = grid_byte(Cache.m_Lat, Cache.m_Long);

	/* since the grid byte matches with what pocketstreets does to   */
	/* input files, our output appears identical to a pin file that  */
    /* has already been processed and corrected by pocketstreets.    */
    /* Due to the grid and signs, it'll look different than one that */
    /* comes straight from S&T.                                      */
	
    /* the grid byte */
    fwrite(&c, 1, 1, m_fd);

    /* 8 bytes - latitude/radians */
	psp_fwrite_double(lat, m_fd);

    /* 8 bytes - longitude/radians */
	psp_fwrite_double(lon, m_fd);

    /* 1 byte - pin properties */
    c = 0x14; /* display pin name on, display notes on. 0x04 = no notes */
    fwrite(&c, 1, 1, m_fd);

    memset(tbuf, '\0', sizeof(tbuf));

    /* 3 unknown bytes */
    fwrite(tbuf, 1, 3, m_fd);

	char Icon[2] = {0,0};

	/*
	Traditional is a red box with a flag
	Mystery Cache is the pushpin.
	Multi is the Flags
	Event is the bubble text icon.
	Virtual is the arrow pointing right.
	*/

	#define	IconPin				0
	#define	IconBubble			1
	#define	IconRedBoxFlag		4
	#define	IconArrowToLeft		8
	#define	IconArrowToRight	9
	#define	IconArrowDown		10
	#define	IconFlags			18
	#define	IconLetter			29

	switch (Cache.TypeLookup())
	{
	case GT_Traditional:
		Icon[0] = IconRedBoxFlag;
		break;
	case GT_Multi:
		Icon[0] = IconFlags;
		break;
	case GT_Virtual:
		Icon[0] = IconArrowToRight;
		break;
	case GT_Webcam:
		Icon[0] = IconArrowDown;
		break;
	case GT_Unknown:
		Icon[0] = IconPin;
		break;
	case GT_LetterboxHybrid:
		Icon[0] = IconLetter;
		break;
	case GT_Event:
		Icon[0] = IconBubble;
		break;
	case GT_ProjectAPE:
		Icon[0] = IconRedBoxFlag;
		break;
	case GT_Locationless:
		Icon[0] = IconArrowToLeft;
		break;
	case GT_CITO:
		Icon[0] = IconBubble;
		break;
	case GT_Earthcache:
		Icon[0] = IconArrowToRight;
		break;
	}

    /* 1 icon byte 0x00 = PIN */
    fwrite(&Icon, 1, 1, m_fd);

    /* 3 unknown bytes */
    fwrite(tbuf, 1, 3, m_fd); /* 3 junk */

	//---------------------------------

	String Desc;

	Desc = Cache.m_Shortname;

	char* pDesc = w2a((TCHAR*) Desc.c_str());

    c = strlen(pDesc);

    /* 1 string size */
    fwrite(&c, 1, 1, m_fd);

    for (i = 0; pDesc[i]; i++) 
	{
		fwrite(&pDesc[i], 1, 1, m_fd);	/* char */
		fwrite(&tbuf[0], 1, 1, m_fd);		/* null */
    }

	//---------------------------------

	Desc = Cache.m_GsCacheType;
	Desc += _T(". ");
	Desc += Cache.m_GsCacheName;
	Desc += _T(" by ");
	Desc += Cache.m_GsCacheOwnerName;
	Desc += _T(". Rating: ");
	Desc += RatingToStringW(Cache.m_GsCacheDifficulty);
	Desc += _T("/");
	Desc += RatingToStringW(Cache.m_GsCacheTerrain);

	TCHAR		Buffer[20];

	Cache.LastFoundText(Buffer);

	Desc += _T(". Last found: ");
	Desc += Buffer;

	pDesc = w2a((TCHAR*) Desc.c_str());

	c = strlen(pDesc);

    /*  1 byte string size */
    fwrite(&c, 1, 1, m_fd);

    for (i = 0; pDesc[i]; i++)
	{
		fwrite(&pDesc[i], 1, 1, m_fd);	/* char */
        fwrite(&tbuf[0], 1, 1, m_fd);	/* null */
    }

	//---------------------------------

	// Scrap the last string

    c = strlen(tbuf);

    /* 1 byte string size */
    fwrite(&c, 1, 1, m_fd);

	for (i = 0; tbuf[i]; i++) 
	{
		fwrite(&tbuf[i], 1, 1, m_fd);              /* char */
		fwrite(&tbuf[0], 1, 1, m_fd);              /* null */
	}
}