Esempio n. 1
0
File: Space.cpp Progetto: GMIS/GMIS
tstring GetFileName(tstring s)
{
	tstring::size_type n = s.find(_T('.'));
	if(n == tstring::npos)return s;
	return s.substr(0,n);
};
Esempio n. 2
0
//
// Query any given "\StringFileInfo\lang-charset\<str>" version info string.
// lang indicates the language translation, may be 0 to signify file default.
// String version. Throws exception on failure. [VH 2005-04-03]
//
tstring TModuleVersionInfo::GetInfoString(const tstring& str, uint lang)
  {LPCTSTR v = _T(""); E = GetInfoString(str.c_str (), v, lang); return v;}
Esempio n. 3
0
static void UnserializeParameter(const tstring& sHandle, const tstring& sValue, CBaseEntity* pEntity)
{
	CSaveData oSaveDataValues;
	CSaveData* pSaveData = CBaseEntity::FindSaveDataValuesByHandle(pEntity->GetClassName(), sHandle.c_str(), &oSaveDataValues);
	TAssert(pSaveData && pSaveData->m_pszHandle);
	if (!pSaveData || !pSaveData->m_pszHandle)
	{
		TError("Unknown handle '" + sHandle + "'\n");
		return;
	}

	if (!pSaveData->m_pfnUnserializeString)
		return;

	pSaveData->m_pfnUnserializeString(sValue, pSaveData, pEntity);
}
/////////////////////////////////////////////////////////////////////
// 
// Function:    
//
// Description: 
//
/////////////////////////////////////////////////////////////////////
BOOL CAMigrateBOINCData::GetFileDirectorySizes( tstring strDirectory, ULONGLONG& ullFileSize, ULONGLONG& ullDirectorySize )
{
    WIN32_FIND_DATA ffData;
    HANDLE          hFind;
    tstring         csPathMask;
    tstring         csFullPath;
    tstring         csNewFullPath;
    
    if ( _T("\\") != strDirectory.substr(strDirectory.length() - 1, 1) )
    {
        strDirectory += _T("\\");
    }
    csPathMask = strDirectory + _T("*.*");

    hFind = FindFirstFile(csPathMask.c_str(), &ffData);

    if (hFind == INVALID_HANDLE_VALUE){
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            _T("CAMigrateBOINCData::GetFileDirectorySizes -- Invalid handle")
        );
        return FALSE;
    }
    
    // Calculating Sizes
    while (hFind && FindNextFile(hFind, &ffData)) 
    {
        if( !(ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) 
        {
            csFullPath  = strDirectory;
            csFullPath += ffData.cFileName;

            // Add current file size to the overall directory size
            ullDirectorySize += ((ffData.nFileSizeHigh * MAXDWORD) + ffData.nFileSizeLow);

            // If this file size is bigger than the one we know about, store it
            //   for later use.
            if (ullFileSize < ((ffData.nFileSizeHigh * MAXDWORD) + ffData.nFileSizeLow)) {
                ullFileSize = ((ffData.nFileSizeHigh * MAXDWORD) + ffData.nFileSizeLow);
            }
        }
        else // it is a directory
        { 
            csNewFullPath  = strDirectory;
            csNewFullPath += ffData.cFileName;
            csNewFullPath += _T("\\");

            if( (_tcscmp(ffData.cFileName, _T(".")) != 0) &&
                (_tcscmp(ffData.cFileName, _T("..")) != 0) ) 
            {
                GetFileDirectorySizes(csNewFullPath, ullFileSize, ullDirectorySize);
            }
        }
    }

    FindClose(hFind);
    return TRUE;
}
/////////////////////////////////////////////////////////////////////
// 
// Function:    
//
// Description: 
//
/////////////////////////////////////////////////////////////////////
BOOL CAMigrateBOINCData::MoveFiles( tstring strSourceDirectory, tstring strDestinationDirectory, ULONGLONG& ullBytesTransfered )
{
    BOOL bRet = TRUE;
    WIN32_FIND_DATA ffData;
    HANDLE hFind;
    tstring csPathMask;
    tstring csFullPath;
    tstring csNewFullPath;
    tstring strMessage;

    strMessage  = _T("CAMigrateBOINCData::MoveFiles -- Directory: '");
    strMessage += strSourceDirectory;
    strMessage += _T("'");

    LogMessage(
        INSTALLMESSAGE_INFO,
        NULL, 
        NULL,
        NULL,
        NULL,
        strMessage.c_str()
    );

    // Create the destination cirectory if needed.
    //
    CreateDirectory(strDestinationDirectory.c_str(), NULL);
    
    if ( _T("\\") != strSourceDirectory.substr(strSourceDirectory.length() - 1, 1) )
    {
        strSourceDirectory       += _T("\\");
    }
    if ( _T("\\") != strDestinationDirectory.substr(strDestinationDirectory.length() - 1, 1) )
    {
        strDestinationDirectory  += _T("\\");
    }
    csPathMask                = strSourceDirectory + _T("*.*");
        
    hFind = FindFirstFile(csPathMask.c_str(), &ffData);

    if (hFind == INVALID_HANDLE_VALUE){
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            _T("CAMigrateBOINCData::MoveFiles -- Invalid handle")
        );
        return FALSE;
    }
    

    // Copying all the files
    while (hFind && FindNextFile(hFind, &ffData)) 
    {
        csFullPath    = strSourceDirectory      + ffData.cFileName;
        csNewFullPath = strDestinationDirectory + ffData.cFileName;

        RemoveReadOnly(csFullPath);
        RemoveReadOnly(csNewFullPath);

        if( !(ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) 
        {
            strMessage  = _T("CAMigrateBOINCData::MoveFiles -- Copy File: '");
            strMessage += csFullPath.c_str();
            strMessage += _T("' to '");
            strMessage += csNewFullPath.c_str();
            strMessage += _T("'");

            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                strMessage.c_str()
            );

            if( !CopyFile(csFullPath.c_str(), csNewFullPath.c_str(), FALSE) ) 
            {
                LogMessage(
                    INSTALLMESSAGE_INFO,
                    NULL, 
                    NULL,
                    NULL,
                    GetLastError(),
                    _T("CAMigrateBOINCData::MoveFiles -- Failed to copy original file")
                );
                bRet = FALSE;
            }
            else
            {
                ullBytesTransfered += ((ffData.nFileSizeHigh * MAXDWORD) + ffData.nFileSizeLow);

                // Specify that an update of the progress bar's position in
                //   this case means to move it forward by one increment.
                MsiRecordSetInteger(m_phProgressRec, 1, 2);
                MsiRecordSetInteger(m_phProgressRec, 2, (INT)((ullBytesTransfered/1024)/1024));
                MsiRecordSetInteger(m_phProgressRec, 3, 0);
                MsiProcessMessage(m_hMSIHandle, INSTALLMESSAGE_PROGRESS, m_phProgressRec);
                Sleep(0);

                // Delete the original file when it has been successfully
                //   copied
                if( !DeleteFile(csFullPath.c_str()) ) 
                {
                    LogMessage(
                        INSTALLMESSAGE_INFO,
                        NULL, 
                        NULL,
                        NULL,
                        GetLastError(),
                        _T("CAMigrateBOINCData::MoveFiles -- Failed to delete original file")
                    );
                }
            }
        }
        else // it is a directory -> Copying recursivly
        { 
            if( (_tcscmp(ffData.cFileName, _T(".")) != 0) &&
                (_tcscmp(ffData.cFileName, _T("..")) != 0) && 
                (!IsDirectoryExcluded(tstring(ffData.cFileName)))) 
            {
                if( !MoveFiles(csFullPath, csNewFullPath, ullBytesTransfered) )
                {
                    LogMessage(
                        INSTALLMESSAGE_INFO,
                        NULL, 
                        NULL,
                        NULL,
                        NULL,
                        _T("CAMigrateBOINCData::MoveFiles -- Failed to copy drectory")
                    );
                    LogMessage(
                        INSTALLMESSAGE_INFO,
                        NULL, 
                        NULL,
                        NULL,
                        NULL,
                        csNewFullPath.c_str()
                    );
                    bRet = FALSE;
                }
            }
        }
    }

    FindClose(hFind);

    RemoveReadOnly(strSourceDirectory);
	RemoveDirectory(strSourceDirectory.c_str());

    return bRet;
}
void ErrorDialog::setItemText(int id, tstring text)
{
    SetWindowText(GetDlgItem(handle, id), text.c_str());
}
Esempio n. 7
0
bool VaultSearchQuery::SetQueryString( const tstring& queryString, tstring& errors )
{
    // Set the QueryString
    m_QueryString = queryString;
    m_SQLQueryString.clear();

    if ( !ParseQueryString( m_QueryString, errors, this ) )
    {
        Log::Warning( TXT( "Errors occurred while parsing the query string: %s\n  %s\n" ), m_QueryString.c_str(), errors.c_str() );
        return false;
    }

    return true;
}
Esempio n. 8
0
//
/// String-aware overload
//
TProfile::TProfile(const tstring& section, const tstring& filename)
{
  Init(
    section.empty() ? 0 : section.c_str(), 
    filename.empty() ? 0 : filename.c_str());
}
Esempio n. 9
0
//
// String-aware overload
//
TWaitableTimer::TWaitableTimer(bool manualReset, const tstring& name, LPSECURITY_ATTRIBUTES sa)
{
  Handle = CreateWaitableTimer(sa, manualReset, name.c_str());
  if (!Handle) throw TXOwl(_T("CreateWaitableTimer failed."));
}
Esempio n. 10
0
/////////////////////////////////////////////////////////////////////
// 
// Function:    
//
// Description: 
//
/////////////////////////////////////////////////////////////////////
tstring CACreateProjectInitFile::ParseParameter(tstring& strSetupExeName, tstring& strParameter)
{
    tstring strParameterName;
    tstring strEncodedValue;
    tstring strParameterValue;
    tstring strError;
    size_t iParameterStart = 0;
    size_t iParameterEnd = 0;

    strParameterName = strParameter + _T("_");

    strError  = _T("Searching for parameter '");
    strError += strParameterName;
    strError += _T("'");

    LogMessage(
        INSTALLMESSAGE_INFO,
        NULL, 
        NULL,
        NULL,
        NULL,
        strError.c_str()
    );

    iParameterStart = strSetupExeName.rfind(strParameterName);
    if (iParameterStart != tstring::npos) {
        iParameterStart += strParameterName.size();
        iParameterEnd = strSetupExeName.find(_T("_"), iParameterStart);
        if (iParameterEnd == tstring::npos) {
            iParameterEnd = strSetupExeName.find(_T("."), iParameterStart);
            if (iParameterEnd == tstring::npos) {
                return tstring(_T(""));
            }
        }
        strEncodedValue = strSetupExeName.substr(iParameterStart, iParameterEnd - iParameterStart);

        strError  = _T("Found encoded value '");
        strError += strEncodedValue;
        strError += _T("'");

        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            strError.c_str()
        );

        // WCG didn't want to have to encode their setup cookie value.  So all parameters but the setup cookie
        // are base64 encoded.
        //
        if (strParameterName == _T("asc_")) {

            strParameterValue = strEncodedValue;

        } else {

            CW2A pszASCIIEncodedValue( strEncodedValue.c_str() );
            CA2W pszUnicodeDecodedValue( r_base64_decode(pszASCIIEncodedValue, strlen(pszASCIIEncodedValue)).c_str() );

            strError  = _T("Decoded value '");
            strError += pszUnicodeDecodedValue;
            strError += _T("'");

            LogMessage(
                INSTALLMESSAGE_INFO,
                NULL, 
                NULL,
                NULL,
                NULL,
                strError.c_str()
            );

            strParameterValue = pszUnicodeDecodedValue;

        }
    }

    strError  = _T("Returning value '");
    strError += strParameterValue;
    strError += _T("'");

    LogMessage(
        INSTALLMESSAGE_INFO,
        NULL, 
        NULL,
        NULL,
        NULL,
        strError.c_str()
    );

    return strParameterValue;
}
Esempio n. 11
0
tstring TriToken(tstring& Token){
	tstring::size_type begin = Token.find_first_not_of(_T(' '));
    if(begin == string::npos)return Token;
    tstring::size_type end = Token.find_last_not_of(_T(' '));
	return Token.substr(begin,end-begin+1);
}
Esempio n. 12
0
void set_srcdir(tstring const& x)
{
    srcdir.assign(x.data(), x.size());
}
Esempio n. 13
0
void set_test_resources_dir(tstring const& x)
{
    top_srcdir.assign(x.data(), x.size());
}
Esempio n. 14
0
 const TCHAR *get_facename() const {
   return facename.c_str();
 }
Esempio n. 15
0
	void Logger::Log(LogLevel level, const tstring& pMessage, const tstring& tag)
	{
#if LOGGER_MIN_LEVEL > 0
		
		tstring levelName;
		switch(level)
		{
		case LogLevel::Info :
			levelName = _T("INFO");
			break;
		case LogLevel::Warning:
			levelName = _T("WARNING");
			break;
		case LogLevel::Error:
			levelName = _T("ERROR");
			break;
		case LogLevel::Debug:
			levelName = _T("DEBUG");
			break;
		}

	#ifdef DESKTOP
		tstringstream messageBuffer;
		messageBuffer << _T("[") << tag << _T("] ") << _T("[") << levelName <<  _T("] ") << pMessage << std::endl;
		tstring combinedMessage = messageBuffer.str();
		
		if(m_UseConsole)
		{
			switch(level)
			{
			case LogLevel::Info :
				#if LOGGER_MIN_LEVEL < 2
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
				#endif
				break;
			case LogLevel::Warning :
				#if LOGGER_MIN_LEVEL < 3
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
				#endif
				break;
			case LogLevel::Error :
				#if LOGGER_MIN_LEVEL < 4
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_RED);
				#endif
				break;
			case LogLevel::Debug :
				#if LOGGER_MIN_LEVEL < 5
				#ifdef DEBUG
				SetConsoleTextAttribute(m_ConsoleHandle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				#endif
				#endif
				break;
			}
			tprintf(combinedMessage.c_str());
		}
		else
		{
			OutputDebugString(combinedMessage.c_str());
		}
		#ifndef NO_LOG_FILE
		LogMessage(combinedMessage);
		#endif
	#else
		switch(level)
		{
		case LogLevel::Info:
			#if LOGGER_MIN_LEVEL < 2
			__android_log_print(ANDROID_LOG_INFO, tag.c_str(), "%s", pMessage.c_str());
			#endif
			break;
		case LogLevel::Warning:
			#if LOGGER_MIN_LEVEL < 3
			__android_log_print(ANDROID_LOG_WARN, tag.c_str(), "%s", pMessage.c_str());
			#endif
			break;
		case LogLevel::Error:
			#if LOGGER_MIN_LEVEL < 4
			__android_log_print(ANDROID_LOG_ERROR, tag.c_str(), "%s", pMessage.c_str());
			#endif
			break;
		case LogLevel::Debug:
			#if LOGGER_MIN_LEVEL < 5
			#ifdef DEBUG
			__android_log_print(ANDROID_LOG_DEBUG, tag.c_str(), pMessage.c_str());
			#endif
			#endif
			break;
		}
		#ifndef NO_LOG_FILE
		tstringstream messageBuffer;
		messageBuffer << _T("[") << tag << _T("] ") << _T("[") << levelName <<  _T("] ") << pMessage << std::endl;
		LogMessage(messageBuffer.str());
		#endif
	#endif
#endif
	}
Esempio n. 16
0
//
// String-aware overload
//
TWaitableTimer::TWaitableTimer(const tstring& name, bool inherit,  uint32 access)
{
  Handle = OpenWaitableTimer(access, inherit, name.c_str());
  if (!Handle) throw TXOwl(_T("OpenWaitableTimer failed."));
}
Esempio n. 17
0
void CGeneralWindow::Paint(float x, float y, float w, float h)
{
	if (m_flFadeToBlack)
	{
		float flAlpha = (float)RemapVal(GameServer()->GetGameTime(), m_flFadeToBlack, m_flFadeToBlack+1.5f, 0.0, 1.0);
		glgui::CRootPanel::PaintRect(0, 0, glgui::CRootPanel::Get()->GetWidth(), glgui::CRootPanel::Get()->GetHeight(), Color(0, 0, 0, (int)(255*flAlpha)));
		return;
	}

	Rect recAntivirus = m_hAntivirus.GetArea("Antivirus");
	glgui::CBaseControl::PaintSheet(m_hAntivirus.GetSheet("Antivirus"), x, y, w, h, recAntivirus.x, recAntivirus.y, recAntivirus.w, recAntivirus.h, m_hAntivirus.GetSheetWidth("Antivirus"), m_hAntivirus.GetSheetHeight("Antivirus"));

	BaseClass::Paint(x, y, w, h);

	if (!m_sEmotion.length())
		return;

	CGameRenderingContext c(GameServer()->GetRenderer(), true);
	c.SetBlend(BLEND_ALPHA);
	c.SetColor(Color(255, 255, 255, 255));

	Rect recEmotion = m_hGeneral.GetArea(m_sEmotion);
	glgui::CBaseControl::PaintSheet(m_hGeneral.GetSheet(m_sEmotion), x, y, 256, 256, recEmotion.x, recEmotion.y, recEmotion.w, recEmotion.h, m_hGeneral.GetSheetWidth(m_sEmotion), m_hGeneral.GetSheetHeight(m_sEmotion));

	if ((m_bHelperSpeaking || m_bProgressBar) && Oscillate((float)GameServer()->GetGameTime(), 0.2f) > 0.5)
	{
		Rect recMouth = m_hGeneralMouth.GetArea(m_sEmotion);
		glgui::CBaseControl::PaintSheet(m_hGeneralMouth.GetSheet(m_sEmotion), x, y, 256, 256, recMouth.x, recMouth.y, recMouth.w, recMouth.h, m_hGeneralMouth.GetSheetWidth(m_sEmotion), m_hGeneralMouth.GetSheetHeight(m_sEmotion));
	}

	if (m_bProgressBar)
	{
		double flTime = 3;
		glgui::CBaseControl::PaintRect(x + m_pText->GetLeft(), y + 160, m_pText->GetWidth(), 10, Color(255, 255, 255, 255));
		glgui::CBaseControl::PaintRect(x + m_pText->GetLeft() + 2, y + 160 + 2, ((m_pText->GetWidth() - 4) * (float)RemapValClamped(GameServer()->GetGameTime(), m_flStartTime, m_flStartTime+flTime, 0.0, 1.0)), 10 - 4, Color(42, 65, 122, 255));

		static tstring sEstimate;
		static double flLastEstimateUpdate = 0;

		if (!sEstimate.length() || GameServer()->GetGameTime() - flLastEstimateUpdate > 1)
		{
			int iRandomTime = RandomInt(0, 5);
			tstring sRandomTime;
			if (iRandomTime == 0)
				sRandomTime = "centuries";
			else if (iRandomTime == 1)
				sRandomTime = "minutes";
			else if (iRandomTime == 2)
				sRandomTime = "hours";
			else if (iRandomTime == 3)
				sRandomTime = "days";
			else
				sRandomTime = "seconds";

			sEstimate = tsprintf(tstring("Estimated time remaining: %d %s"), RandomInt(2, 100), sRandomTime.c_str());

			flLastEstimateUpdate = GameServer()->GetGameTime();
		}

		float flWidth = glgui::RootPanel()->GetTextWidth(sEstimate, sEstimate.length(), "sans-serif", 12);
		glgui::CLabel::PaintText(sEstimate, sEstimate.length(), "sans-serif", 12, x + m_pText->GetLeft() + m_pText->GetWidth()/2 - flWidth/2, (float)y + 190, Color(0, 0, 0, 255));
	}
}
Esempio n. 18
0
inline void SetWindowText (HWND hwnd, const tstring& ts) { SetWindowText(hwnd, ts.c_str()); }
Esempio n. 19
0
int Win32DebugAppender::append(const tstring &logMsg)
{
	OutputDebugString(logMsg.c_str());
	return 0;
}
Esempio n. 20
0
inline void SetDlgItemText (HWND hwnd, int i, const tstring& ts) { SetDlgItemText(hwnd, i, ts.c_str()); }
Esempio n. 21
0
	path(const tstring &p) { StringCbCopy(this->buf, sizeof(this->buf), p.c_str()); }
Esempio n. 22
0
void Script::ParseAttributes(tstring& attributes, Control* control)
{
  INSPECT_SCOPE_TIMER( ("Attributes Script Attribute Processing") );
  
  size_t pos = 0;
  size_t end = tstring::npos;

  while (pos < attributes.length() && pos != tstring::npos)
  {
    // eat ws
    pos = attributes.find_first_not_of(LS_WHITESPACE, pos);

    // the rest is WS, abort
    if (pos == tstring::npos)
      break;

    // search for end of keyword
    end = attributes.find_first_of(LS_WHITESPACE TXT( "=" ), pos);

    // we have no symbol term, just abort
    if (end == tstring::npos)
      break;

    // copy just our symbol into a string
    tstring key (attributes.data() + pos, end - pos);

    // next tchar_t
    pos = end+1;

    // eat ws
    pos = attributes.find_first_not_of(LS_WHITESPACE, pos);

    // the rest is WS, abort
    if (pos == tstring::npos)
      break;

    // see if the value is directly quoted
    size_t startQuote = attributes.find_first_of( TXT( "\"" ), pos);
    size_t endQuote = attributes.find_first_of( TXT( "\"" ), startQuote+1);

    // search for end of keyword
    end = attributes.find_first_of( TXT( ";" ), pos);

    // if the semi is in the quote
    if (startQuote != tstring::npos && endQuote != tstring::npos && startQuote < end && end < endQuote)
    {
      // search for end of value not quoted
      end = attributes.find_first_of( TXT( ";" ), endQuote);
    }

    // we have no symbol term, just abort
    if (end == tstring::npos)
    {
      end = attributes.length();
    }

    // copy just our symbol into a string
    tstring value (attributes.data() + pos, end - pos);

    // next tchar_t
    pos = end+1;

    // trim quoted values
    {
      size_t start = value.find_first_of('\"');
      size_t finish = value.find_last_of('\"');

      if (start != tstring::npos)
      {
        if (start == finish)
        {
          value.erase(start, 1);
        }
        else if (start < finish)
        {
          value = value.substr(start + 1, finish - start - 1);
        }
      }
    }

    // insert
    control->Process(key, value);
  }
}
BOOL CAMigrateBOINCData::GetFreeDiskSpace( tstring strDirectory, ULONGLONG& ullFreeSpace )
{
    ULARGE_INTEGER          TotalNumberOfFreeBytes;
    ULARGE_INTEGER          TotalNumberOfBytes;
    ULARGE_INTEGER          TotalNumberOfBytesFreeToCaller;
    DWORD                   dwSectPerClust = NULL;
    DWORD                   dwBytesPerSect = NULL;
    DWORD                   dwFreeClusters = NULL;
    DWORD                   dwTotalClusters = NULL;
    BOOL                    bReturnValue = FALSE;
    MyGetDiskFreeSpaceEx    pGetDiskFreeSpaceEx = NULL;
    TCHAR                   szMessage[2048];

#ifdef _UNICODE
    pGetDiskFreeSpaceEx = (MyGetDiskFreeSpaceEx)GetProcAddress(
        GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExW"
    );
#else
    pGetDiskFreeSpaceEx = (MyGetDiskFreeSpaceEx)GetProcAddress(
        GetModuleHandle("kernel32.dll"), "GetDiskFreeSpaceExA"
    );
#endif

    _sntprintf(
        szMessage, 
        sizeof(szMessage),
        _T("GetFreeDiskSpace Directory Location: '%s'"),
        strDirectory.c_str()
    );
    LogMessage(
        INSTALLMESSAGE_INFO,
        NULL, 
        NULL,
        NULL,
        NULL,
        szMessage
    );

    if (pGetDiskFreeSpaceEx) {

        if (0 == strDirectory.length())
        {
            bReturnValue = pGetDiskFreeSpaceEx(
                NULL,
                &TotalNumberOfBytesFreeToCaller,
                &TotalNumberOfBytes,
                &TotalNumberOfFreeBytes
            );
        }
        else
        {
            bReturnValue = pGetDiskFreeSpaceEx(
                strDirectory.c_str(),
                &TotalNumberOfBytesFreeToCaller,
                &TotalNumberOfBytes,
                &TotalNumberOfFreeBytes
            );
        }

        _sntprintf(
            szMessage, 
            sizeof(szMessage),
            _T("GetDiskFreeSpaceEx Return Value: '%d'"),
            bReturnValue
        );
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            szMessage
        );

        _sntprintf(
            szMessage, 
            sizeof(szMessage),
            _T("GetDiskFreeSpaceEx GetLastError: '%d'"),
            GetLastError()
        );
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            szMessage
        );

        _sntprintf(
            szMessage, 
            sizeof(szMessage),
            _T("TotalNumberOfFreeBytes: '%I64u'"),
            TotalNumberOfFreeBytes.QuadPart
        );
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            szMessage
        );

        ullFreeSpace = TotalNumberOfFreeBytes.QuadPart;

    }
    else
    {

        if (0 == strDirectory.length())
        {
            bReturnValue = GetDiskFreeSpace(
                NULL,
                &dwSectPerClust,
                &dwBytesPerSect,
                &dwFreeClusters,
                &dwTotalClusters
            );
        }
        else
        {
            bReturnValue = GetDiskFreeSpace(
                strDirectory.c_str(),
                &dwSectPerClust,
                &dwBytesPerSect,
                &dwFreeClusters,
                &dwTotalClusters
            );
        }

        _sntprintf(
            szMessage, 
            sizeof(szMessage),
            _T("GetDiskFreeSpace Return Value: '%d'"),
            bReturnValue
        );
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            szMessage
        );

        _sntprintf(
            szMessage, 
            sizeof(szMessage),
            _T("GetDiskFreeSpace GetLastError: '%d'"),
            GetLastError()
        );
        LogMessage(
            INSTALLMESSAGE_INFO,
            NULL, 
            NULL,
            NULL,
            NULL,
            szMessage
        );

        ullFreeSpace = dwFreeClusters * dwSectPerClust * dwBytesPerSect;
    }

    return bReturnValue;
}
Esempio n. 24
0
HWND WEdit::Create(const tstring& windowText, int x, int y, int nWidth, int nHeight, HWND hWndParent)
{
    hWnd_ = CreateWindow("EDIT", windowText.c_str(), WS_CHILD|WS_VISIBLE|WS_BORDER, x, y, nWidth, nHeight, hWndParent, NULL, GetModuleHandle(NULL), this);   
    ChangeWndProc();
    return hWnd_;
}
Esempio n. 25
0
int Helium::Execute( const tstring& command, tstring& output, bool showWindow )
{
    HANDLE hReadPipe;
    HANDLE hWritePipe;
    SECURITY_ATTRIBUTES sa;
    sa.nLength              = sizeof(sa);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle       = TRUE;
    if( !CreatePipe( &hReadPipe, &hWritePipe, &sa, 0 ) )
    {
        return -1;
    }

    STARTUPINFO          si;
    memset( &si, 0, sizeof(si) );
    si.cb          = sizeof(si);
    si.dwFlags     = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    si.wShowWindow = static_cast<int>( showWindow );
    si.hStdOutput  = hWritePipe;
    si.hStdError   = hWritePipe;      

    PROCESS_INFORMATION  pi;
    memset( &pi, 0, sizeof( pi ) );

    if( !CreateProcess(
        NULL,                                                 // filename
        (tchar*) command.c_str(),                               // command line for child
        NULL,                                                 // process security descriptor
        NULL,                                                 // thread security descriptor
        TRUE,                                                 // inherit handles?
        showWindow ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW,   // creation flags
        NULL,                                                 // inherited environment address
        NULL,                                                 // startup dir; NULL = start in current
        &si,                                                  // pointer to startup info (input)
        &pi ) )                                               // pointer to process info (output)
    {
        ::CloseHandle( hReadPipe );
        ::CloseHandle( hWritePipe );
        return -1;
    }

    // close the write end of the pipe so the child will terminate it with EOF
    ::CloseHandle( hWritePipe );

    // read from the pipe until EOF condition reached
    tchar buffer[80];
    unsigned long count;
    tstringstream stream;
    BOOL success = TRUE;
    do
    {
        while ( success = ReadFile( hReadPipe, buffer, sizeof(buffer), &count, NULL ) )
        {
            if( success )
            {
                stream.write( buffer, count );
            }
            else
            {
                if ( ::GetLastError() == ERROR_BROKEN_PIPE )
                {
                    break;
                }
                else
                {
                    return -1;
                }
            }
        }
    } while( success && count );

    // done reading, close our read pipe
    ::CloseHandle( hReadPipe );

    // copy output string
    output = stream.str();

    // get exit code
    DWORD result = 0;
    BOOL codeResult = ::GetExitCodeProcess( pi.hProcess, &result );
    HELIUM_ASSERT( codeResult );

    // close the process handle
    ::CloseHandle( pi.hProcess );
    ::CloseHandle( pi.hThread );

    return result;
}
Esempio n. 26
0
// HKEY_CLASSES_ROOT
//    FileMarker.AVI - AVI - Windows 기본 비디오 파일
//       shell
// 	       Mark - Daum 팟플레이어의 재생목록(&I)에 추가하기
// 		    command - "C:\Program Files (x86)\DAUM\PotPlayer\PotPlayer.exe" "%1" /ADD
bool CRegisterMenu::Register(const tstring& strAppName, tstring strExt, 
                             tstring strMenu, tstring strMenuDisplay, 
                             tstring strCommand, tstring strDesc)
{
  if (strAppName.empty() || strExt.empty() || strDesc.empty() || 
      strMenu.empty() || strMenuDisplay.empty() || strCommand.empty())
    return false;

  if (!RegisterExtKey(strExt, strMenu, strMenuDisplay, strCommand))
    return false;

  // remove '.'
  strExt.erase(std::remove(strExt.begin(), strExt.end(), _T('.')), strExt.end());

  // Uppercase extension
  CStringUtil::MakeUpper(strExt);
  tstring strAppExt = strAppName + _T(".") + strExt;

  LPCTSTR strSubKeys[] = { strAppExt.c_str(), 
                           _T("shell"), 
                           strMenu.c_str(), 
                           _T("command") };

  LPCTSTR strValues[] = { strDesc.c_str(),
                          _T(""),
                          strMenuDisplay.c_str(),
                          strCommand.c_str() };

  tstring strSubKey;
  tstring strValue;
  for (int i = 0; i < _countof(strSubKeys); ++i)
  {
    strSubKey += strSubKeys[i];
    strSubKey += _T("\\");
    strValue = strValues[i];

    if (!RegisterMenu(strSubKey, strValue))
      return false;
  }

//	SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, NULL, NULL);

  return true;
}
Esempio n. 27
0
void CApplication::PrintError(const tstring& sText)
{
	tstring sTrimmedText = trim(sText);

	GetConsole()->PrintConsole(tstring("[color=FF0000]ERROR: ") + sTrimmedText + "[/color]" + (sText.endswith("\n")?"\n":""));
}
Esempio n. 28
0
LRESULT EmoticonsDlg::onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	ShowWindow(SW_HIDE);
	WNDPROC temp = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(EmoticonsDlg::m_hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(NewWndProc)));
	if (!g_MFCWndProc)
		g_MFCWndProc = temp;
	g_pDialog = this;
	::EnableWindow(WinUtil::g_mainWnd, true);
	
	bool bUseAnimation = BOOLSETTING(SMILE_SELECT_WND_ANIM_SMILES);
	
	if (CAGEmotionSetup::g_pEmotionsSetup)
	{
		const CAGEmotion::Array& Emoticons = CAGEmotionSetup::g_pEmotionsSetup->getEmoticonsArray();
		unsigned int pocet = 0;
		int l_count_emotion = 0;
		string lastEmotionPath, lastAnimEmotionPath;
		for (auto pEmotion = Emoticons.cbegin();
		        pEmotion != Emoticons.cend() && l_count_emotion < CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions;
		        ++pEmotion, ++l_count_emotion)
		{
			if (bUseAnimation)
			{
				if ((*pEmotion)->getEmotionBmpPath() != lastEmotionPath || (*pEmotion)->getEmotionGifPath() != lastAnimEmotionPath)
					pocet++;
					
				lastEmotionPath = (*pEmotion)->getEmotionBmpPath();
				lastAnimEmotionPath = (*pEmotion)->getEmotionGifPath();
			}
			else
			{
				if ((*pEmotion)->getEmotionBmpPath() != lastEmotionPath)
					pocet++;
				lastEmotionPath = (*pEmotion)->getEmotionBmpPath();
			}
		}
		
		// x, y jen pro for cyklus
		const unsigned int l_Emoticons_size = CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions;
		unsigned int i = (unsigned int)sqrt(double(l_Emoticons_size));
		unsigned int nXfor = i;
		unsigned int nYfor = i;
		
		if ((i * i) != l_Emoticons_size) //[+]PPA
		{
			nXfor = i + 1;
			if ((i * nXfor) < l_Emoticons_size) nYfor = i + 1;
			else nYfor = i;
		}
		// x, y pro korektni vkladani ikonek za sebou
		i = (unsigned int)sqrt((double)pocet);
		unsigned int nX = i;
		unsigned int nY = i;
		if ((i * i) != pocet) //[+]PPA
		{
			nX = i + 1;
			if ((i * nX) < pocet) nY = i + 1;
			else nY = i;
		}
		if (Emoticons.empty() || !*Emoticons.begin()) //[+]PPA
			return 0;
			
		// [~] brain-ripper
		// If first icon failed to load, h_bm will be zero, and all icons will be drawn extremely small.
		// So cycle through Emoticons and find first loaded icon.
		//HBITMAP h_bm = (*Emoticons.begin())->getEmotionBmp(GetSysColor(COLOR_BTNFACE));
		
		DWORD iSW = 0, iSH = 0, dwCount = 0;
		l_count_emotion = 0;
		for (auto i = Emoticons.cbegin(); i != Emoticons.cend() && l_count_emotion < CAGEmotionSetup::g_pEmotionsSetup->m_CountSelEmotions; ++i, ++l_count_emotion)
		{
			int w = 0, h = 0;
			CGDIImage *pImage = nullptr;
			
			if (bUseAnimation)
				pImage = (*i)->getAnimatedImage(MainFrame::getMainFrame()->m_hWnd, WM_ANIM_CHANGE_FRAME);
				
			if (pImage)
			{
				w = pImage->GetWidth();
				h = pImage->GetHeight();
				dwCount++;
			}
			else
			{
				if ((*i)->getDimensions(&w, &h))
				{
					if (bUseAnimation)
						dwCount++;
					else
					{
						iSW = w;
						iSH = h;
						break;
					}
				}
			}
			
			iSW += w * w;
			iSH += h * h;
		}
		
		if (bUseAnimation && dwCount)
		{
			// Get mean square of all icon dimensions
			iSW = DWORD(sqrt(float(iSW / dwCount)));
			iSH = DWORD(sqrt(float(iSH / dwCount)));
		}
		
		pos.bottom = pos.top - 3;
		pos.left = pos.right - nX * (iSW + EMOTICONS_ICONMARGIN) - 2;
		pos.top = pos.bottom - nY * (iSH + EMOTICONS_ICONMARGIN) - 2;
		
		// [+] brain-ripper
		// Fit window in screen's work area
		RECT rcWorkArea;
		SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
		if (pos.right > rcWorkArea.right)
		{
			pos.left -= pos.right - rcWorkArea.right;
			pos.right = rcWorkArea.right;
		}
		if (pos.bottom > rcWorkArea.bottom)
		{
			pos.top -= pos.bottom - rcWorkArea.bottom;
			pos.bottom = rcWorkArea.bottom;
		}
		if (pos.left < rcWorkArea.left)
		{
			pos.right += rcWorkArea.left - pos.left;
			pos.left = rcWorkArea.left;
		}
		if (pos.top < rcWorkArea.top)
		{
			pos.bottom += rcWorkArea.top - pos.top;
			pos.top = rcWorkArea.top;
		}
		
		MoveWindow(pos);
		
		lastEmotionPath.clear();
		lastAnimEmotionPath.clear();
		
		m_ctrlToolTip.Create(EmoticonsDlg::m_hWnd, rcDefault, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON, WS_EX_TOPMOST);
		m_ctrlToolTip.SetDelayTime(TTDT_AUTOMATIC, 1000);
		
		pos.left = 0;
		pos.right = iSW + EMOTICONS_ICONMARGIN;
		pos.top = 0;
		pos.bottom = iSH + EMOTICONS_ICONMARGIN;
		
		cleanHandleList();
		auto l_Emotion = Emoticons.begin();
		for (unsigned int iY = 0; iY < nYfor; iY++)
			for (unsigned int iX = 0; iX < nXfor; iX++)
			{
				if (l_Emotion != Emoticons.end()) // TODO - merge
				{
				
					const auto i = *l_Emotion;
					if ((iY * nXfor) + iX + 1 > l_Emoticons_size) break;
					
					bool bNotDuplicated = (bUseAnimation ?
					                       (i->getEmotionBmpPath() != lastEmotionPath ||
					                        i->getEmotionGifPath() != lastAnimEmotionPath) :
					                       i->getEmotionBmpPath() != lastEmotionPath);
					                       
					                       
					// dve stejne emotikony za sebou nechceme
					if (bNotDuplicated)
					{
						bool bCreated = false;
						CGDIImage *pImage = nullptr;
						
						if (bUseAnimation)
							pImage = i->getAnimatedImage(MainFrame::getMainFrame()->m_hWnd, WM_ANIM_CHANGE_FRAME);
							
						if (pImage)
						{
							const tstring smajl = i->getEmotionText();
							CAnimatedButton *pemoButton = new CAnimatedButton(pImage);
							m_BtnList.push_back(pemoButton);
							pemoButton->Create(EmoticonsDlg::m_hWnd, pos, smajl.c_str(), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | BS_FLAT | BS_BITMAP, WS_EX_TRANSPARENT);
							m_ctrlToolTip.AddTool(*pemoButton, smajl.c_str());
							bCreated = true;
						}
						else
						{
							if (const HBITMAP l_h_bm = i->getEmotionBmp(GetSysColor(COLOR_BTNFACE)))
							{
								CButton emoButton;
								const tstring smajl = i->getEmotionText();
								emoButton.Create(EmoticonsDlg::m_hWnd, pos, smajl.c_str(), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | BS_FLAT | BS_BITMAP | BS_CENTER);
								m_HandleList.push_back(l_h_bm);
								emoButton.SetBitmap(l_h_bm);
								m_ctrlToolTip.AddTool(emoButton, smajl.c_str());
								DeleteObject((HGDIOBJ)emoButton);
								bCreated = true;
							}
						}
						
						if (bCreated)
						{
							// Calculate position of next button
							pos.left = pos.left + iSW + EMOTICONS_ICONMARGIN;
							pos.right = pos.left + iSW + EMOTICONS_ICONMARGIN;
							if (pos.left >= (LONG)(nX * (iSW + EMOTICONS_ICONMARGIN)))
							{
								pos.left = 0;
								pos.right = iSW + EMOTICONS_ICONMARGIN;
								pos.top = pos.top + iSH + EMOTICONS_ICONMARGIN;
								pos.bottom = pos.top + iSH + EMOTICONS_ICONMARGIN;
							}
						}
					}
					
					lastEmotionPath = i->getEmotionBmpPath();
					
					if (bUseAnimation)
						lastAnimEmotionPath = i->getEmotionGifPath();
					++l_Emotion;
				}
			}
			
		pos.left = -128;
		pos.right = pos.left;
		pos.top = -128;
		pos.bottom = pos.top;
		CButton emoButton;
		emoButton.Create(EmoticonsDlg::m_hWnd, pos, _T(""), WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | BS_FLAT);
		emoButton.SetFocus();
		DeleteObject((HGDIOBJ)emoButton);
		ShowWindow(SW_SHOW);
		
		for (auto i = m_BtnList.cbegin(); i != m_BtnList.cend(); ++i)
		{
			(*i)->Update();
		}
	}
	else PostMessage(WM_CLOSE);
	
	return 0;
}
Esempio n. 29
0
void Plugins::GetExports(const tstring &pathToDll, bool displayInfo)
{
  vector<unsigned char> dlldata;
  PIMAGE_NT_HEADERS NTHeaders;
  try {
    read_file(pathToDll, dlldata);
    NTHeaders = CResourceEditor::GetNTHeaders(&dlldata[0]);
  } catch (std::runtime_error&) {
    return;
  }

  tstring dllName = remove_file_extension(get_file_name(pathToDll));
#ifdef _UNICODE
  bool unicodeDll = dllName[dllName.size()-1] == 'W';
#endif

  FIX_ENDIAN_INT16_INPLACE(NTHeaders->FileHeader.Characteristics);
  if (NTHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL)
  {
    FIX_ENDIAN_INT32_INPLACE(NTHeaders->OptionalHeader.NumberOfRvaAndSizes);
    if (NTHeaders->OptionalHeader.NumberOfRvaAndSizes <= IMAGE_DIRECTORY_ENTRY_EXPORT) return;

    DWORD ExportDirVA = NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
    DWORD ExportDirSize = NTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
    PIMAGE_SECTION_HEADER sections = IMAGE_FIRST_SECTION(NTHeaders);

    FIX_ENDIAN_INT32_INPLACE(ExportDirVA);
    FIX_ENDIAN_INT32_INPLACE(ExportDirSize);

    WORD num_sections = FIX_ENDIAN_INT16(NTHeaders->FileHeader.NumberOfSections);

    for (DWORD i = 0; i < num_sections; i++)
    {
      DWORD va = FIX_ENDIAN_INT32(sections[i].VirtualAddress);
      if (va <= ExportDirVA
          && va + FIX_ENDIAN_INT32(sections[i].Misc.VirtualSize) >= ExportDirVA + ExportDirSize)
      {
        DWORD prd = FIX_ENDIAN_INT32(sections[i].PointerToRawData);
        PIMAGE_EXPORT_DIRECTORY exports = PIMAGE_EXPORT_DIRECTORY(&dlldata[0] + prd + ExportDirVA - va);
        DWORD na = FIX_ENDIAN_INT32(exports->AddressOfNames);
        LPDWORD names = (LPDWORD)((ULONG_PTR)exports + na - ExportDirVA);
        for (DWORD j = 0; j < FIX_ENDIAN_INT32(exports->NumberOfNames); j++)
        {
          const string name = string((char*)exports + FIX_ENDIAN_INT32(names[j]) - ExportDirVA);
          const tstring signature = dllName + _T("::") + tstring(CtoTString(name));
          const tstring lcsig = lowercase(signature);
          m_command_to_path[lcsig] = pathToDll;
          m_command_lowercase_to_command[lcsig] = signature;
#ifdef _UNICODE
          const tstring lcsigA = lowercase(dllName.substr(0,dllName.size()-1) + _T("::") + tstring(CtoTString(name)));
          if (unicodeDll && m_command_to_path.find(lcsigA) != m_command_to_path.end())
            m_unicode_variant[lcsigA] = signature;
          else
#endif
          if (displayInfo)
            _ftprintf(g_output, _T(" - %s\n"), signature.c_str());
        }
        break;
      }
    }
  }
}
Esempio n. 30
0
 gcc_pure
 const TCHAR *GetName() const {
   return name.c_str();
 }