Пример #1
0
HANDLE _CreateFile2( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile )
{
	HANDLE hFile =  ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile );
	if( hFile == INVALID_HANDLE_VALUE ){
		TCHAR* p = (TCHAR*)_tcsrchr(lpFileName, '\\');
		TCHAR* szDirPath = NULL;
		if( p != NULL ){
			int iSize = (int)(p - lpFileName);
			szDirPath = new TCHAR[iSize+1];
			_tcsncpy_s(szDirPath, iSize+1, lpFileName, iSize);
		}
		if( szDirPath != NULL ){
			_CreateDirectory(szDirPath);
			delete[] szDirPath;
			hFile =  ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile );
		}
	}
	return hFile;
}
Пример #2
0
//  ---------------------------------------------------------------------------
HRESULT STDMETHODCALLTYPE MFilterSAX2ContentHandler::characters(
  /* [in] */ const wchar_t __RPC_FAR *pwchChars,
  /* [in] */ int cchChars)
{
  if (m_bValidation)
    return S_OK;

  TCHAR* szData = new TCHAR[cchChars + 2];

  _tcsncpy_s(szData, cchChars + 2, pwchChars, cchChars);

  szData[cchChars]=0;
  m_sxElemContent += szData;

  delete [] szData;
  szData = NULL;

  return S_OK;
}
Пример #3
0
// Gets a STRING value for the active key
bool RegKey::GetValue(LPCTSTR pszValueName, LPTSTR pszValue, DWORD& dwValueLength)
{
	TCHAR* tmpBuffer = new TCHAR[dwValueLength + 1];
	memset(tmpBuffer, 0, dwValueLength * sizeof(TCHAR));

	if (!IntGetValue(pszValueName, (BYTE&)*tmpBuffer, dwValueLength))
	{
		delete[] tmpBuffer;
		tmpBuffer = NULL;
		return false;
	}

	_tcsncpy_s(pszValue, dwValueLength + 1, tmpBuffer, dwValueLength);
	delete[] tmpBuffer;
	tmpBuffer = NULL;

	iLastErrorCode_ = ERROR_SUCCESS;
	return true;
}
Пример #4
0
int CExchangeServer::Connect(int bForceConnect)
{
	int maxRetries = db_get_b(NULL, ModuleName, "MaxRetries", MAX_EXCHANGE_CONNECT_RETRIES);
	if (bForceConnect) {
		bTryConnect = 1;
		cConnections = 0;
	}
		
	if (cConnections >= maxRetries) {
		bTryConnect = 0;
		cConnections = 0;
		_popupUtil("Maximum number of retries reached.\nPlugin will stop trying to connect automatically.");
	}

	if (bTryConnect)
		cConnections++;
		
	if ((bTryConnect) && !IsServerAvailable()) {
		bTryConnect = 0;
		_popupUtil("Server not available");
	}		
		
	if ( !IsConnected() && bTryConnect) {
		TCHAR user[1024]; //lovely
		TCHAR password[1024]; //i know
		TCHAR server[1024];

		GetStringFromDatabase("Username", _T(""), user, _countof(user));
		if (ServiceExists(MS_UTILS_REPLACEVARS))
			_tcsncpy_s(user, VARST(user), _TRUNCATE);

		GetStringFromDatabase("Password", _T(""), password, _countof(password));
		GetStringFromDatabase("Server", _T(""), server, _countof(server));

		int port = db_get_dw(NULL, ModuleName, "Port", EXCHANGE_PORT);
		if (_tcslen(server) > 0) //only connect if there's a server to connect to
			return DoConnect(user, password, server, port);			

		_popupUtil("Server is not configured...");
	}
	return -1; //0 on success, != 0 otherwise
}
Пример #5
0
static __forceinline TCHAR* GetPathVarX(const TCHAR*, int code)
{
	TCHAR szFullPath[MAX_PATH];

	switch(code) {
	case 1:
		if (hAvatarFolder != NULL)
			_tcsncpy_s(szFullPath, tszAvatarRoot, _TRUNCATE);
		else
			mir_sntprintf(szFullPath, _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName);
		break;
	case 2:
		mir_sntprintf(szFullPath, _T("%s\\%s\\Logs"), g_profileDir, g_shortProfileName);
		break;
	case 3:
		mir_sntprintf(szFullPath, _T("%s\\%s"), g_profileDir, g_shortProfileName);
		break;
	}
	return mir_tstrdup(szFullPath);
}
Пример #6
0
TCHAR* GetContactFolder(TCHAR *fn, MCONTACT hContact)
{
	char *proto = GetContactProto(hContact);
	GetProtocolFolder(fn, proto);
	
	TCHAR uin[MAX_PATH];
	ptrT id(Contact_GetInfo(CNF_UNIQUEID, hContact, proto));
	_tcsncpy_s(uin, (id == NULL) ? TranslateT("Unknown UIN") : id, _TRUNCATE);
	ConvertToFilename(uin, MAX_PATH); //added so that weather id's like "yw/CI0000" work
	mir_sntprintf(fn, MAX_PATH, _T("%s\\%s"), fn, uin);
	CreateDirectoryTreeT(fn);
	
#ifdef DBGPOPUPS
	TCHAR log[1024];
	mir_sntprintf(log, _T("Path: %s\nProto: %S\nUIN: %s"), fn, proto, uin);
	ShowPopup(hContact, _T("AVH Debug: GetContactFolder"), log);
#endif

	return fn;
}
Пример #7
0
//-----------------------------------------------------------------------------
// Name: DXUtil_ReadStringRegKeyCch()
// Desc: Helper function to read a registry key string
//       cchDest is the size in TCHARs of strDest.  Be careful not to 
//       pass in sizeof(strDest) on UNICODE builds.
//-----------------------------------------------------------------------------
HRESULT DXUtil_ReadStringRegKeyCch( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, 
                                    DWORD cchDest, TCHAR* strDefault )
{
    DWORD dwType;
    DWORD cbDest = cchDest * sizeof(TCHAR);

    if( ERROR_SUCCESS != RegQueryValueEx( hKey, strRegName, 0, &dwType, 
                                          (BYTE*)strDest, &cbDest ) )
    {
        _tcsncpy_s( strDest, cchDest, strDefault, cchDest );
        strDest[cchDest-1] = 0;

        if( dwType != REG_SZ )
            return E_FAIL;

        return S_OK;
    }

    return E_FAIL;
}
Пример #8
0
int CreateFromFontSettings(FontSettingsT *fs, LOGFONT *lf)
{
	GetDefaultFontSetting(lf, 0);

	_tcsncpy_s(lf->lfFaceName, fs->szFace, _TRUNCATE);

	lf->lfWidth = lf->lfEscapement = lf->lfOrientation = 0;
	lf->lfWeight = fs->style & DBFONTF_BOLD ? FW_BOLD : FW_NORMAL;
	lf->lfItalic = (fs->style & DBFONTF_ITALIC) != 0;
	lf->lfUnderline = (fs->style & DBFONTF_UNDERLINE) != 0;
	lf->lfStrikeOut = (fs->style & DBFONTF_STRIKEOUT) != 0;
	lf->lfCharSet = fs->charset;
	lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
	lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
	lf->lfQuality = DEFAULT_QUALITY;
	lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;

	lf->lfHeight = fs->size;
	return 0;
}
Пример #9
0
HRESULT WINAPI NVUTFindDXSDKMediaFileCchT( LPTSTR strDestPath, int cchDest, LPCTSTR strFilename )
{
    HRESULT hr(S_OK);
    USES_CONVERSION;

    CT2W wstrFileName(strFilename);
    LPWSTR wstrDestPath = new WCHAR[cchDest];
    
    hr = NVUTFindDXSDKMediaFileCch(wstrDestPath, cchDest, wstrFileName);
    
    if(!FAILED(hr))
    {
        LPTSTR tstrDestPath = W2T(wstrDestPath);
        _tcsncpy_s(strDestPath, cchDest, tstrDestPath, cchDest);
    }

    delete[] wstrDestPath;

    return hr;
}
Пример #10
0
/*! メニューラベルの作成
	@date 2007.02.22 ryoji デフォルト機能割り当てに関する処理を追加
	2010/5/17	アクセスキーの追加
	@date 2014.05.04 Moca LABEL_MAX=256 => nLabelSize
*/
TCHAR* CKeyBind::GetMenuLabel(
		HINSTANCE	hInstance,
		int			nKeyNameArrNum,
		KEYDATA*	pKeyNameArr,
		int			nFuncId,
		TCHAR*      pszLabel,   //!< [in,out] バッファは256以上と仮定
		const TCHAR*	pszKey,
		BOOL		bKeyStr,
		int			nLabelSize,
		BOOL		bGetDefFuncCode /* = TRUE */
)
{
	const unsigned int LABEL_MAX = nLabelSize;


	if( _T('\0') == pszLabel[0] ){
		_tcsncpy( pszLabel, LS( nFuncId ), LABEL_MAX - 1 );
		pszLabel[ LABEL_MAX - 1 ] = _T('\0');
	}
	if( _T('\0') == pszLabel[0] ){
		_tcscpy( pszLabel, _T("-- undefined name --") );
	}
	// アクセスキーの追加	2010/5/17 Uchi
	_tcsncpy_s( pszLabel, LABEL_MAX, MakeMenuLabel( pszLabel, pszKey ), _TRUNCATE );

	/* 機能に対応するキー名を追加するか */
	if( bKeyStr ){
		CNativeT    cMemAccessKey;
		// 2010.07.11 Moca メニューラベルの「\t」の付加条件変更
		// [ファイル/フォルダ/ウィンドウ一覧以外]から[アクセスキーがあるときのみ]に付加するように変更
		/* 機能に対応するキー名の取得 */
		if( GetKeyStr( hInstance, nKeyNameArrNum, pKeyNameArr, cMemAccessKey, nFuncId, bGetDefFuncCode ) ){
			// バッファが足りないときは入れない
			if( _tcslen( pszLabel ) + (Int)cMemAccessKey.GetStringLength() + 1 < LABEL_MAX ){
				_tcscat( pszLabel, _T("\t") );
				_tcscat( pszLabel, cMemAccessKey.GetStringPtr() );
			}
		}
	}
	return pszLabel;
}
Пример #11
0
void __fastcall Prepare(KN_FP_MASK* mask, bool bEnable)
{
	mask->szMaskUpper = NULL;

	if (mask->hIcolibItem)
		IcoLib_RemoveIcon(mask->szIconName);
	mask->hIcolibItem = NULL;

	if (!mask->szMask || !bEnable)
		return;

	size_t iMaskLen = mir_tstrlen(mask->szMask) + 1;
	LPTSTR pszNewMask = (LPTSTR)HeapAlloc(hHeap, HEAP_NO_SERIALIZE, iMaskLen * sizeof(TCHAR));
	_tcscpy_s(pszNewMask, iMaskLen, mask->szMask);
	_tcsupr_s(pszNewMask, iMaskLen);
	mask->szMaskUpper = pszNewMask;

	TCHAR destfile[MAX_PATH];
	if (mask->iIconIndex == IDI_NOTFOUND || mask->iIconIndex == IDI_UNKNOWN || mask->iIconIndex == IDI_UNDETECTED)
		GetModuleFileName(g_hInst, destfile, MAX_PATH);
	else {
		_tcsncpy_s(destfile, g_szSkinLib, _TRUNCATE);

		struct _stat64i32 stFileInfo;
		if (_tstat(destfile, &stFileInfo) == -1)
			return;
	}

	LPTSTR SectName = getSectionName(mask->iSectionFlag);
	if (SectName == NULL)
		return;

	SKINICONDESC sid = { 0 };
	sid.flags = SIDF_ALL_TCHAR;
	sid.section.t = SectName;
	sid.pszName = mask->szIconName;
	sid.description.t = mask->szClientDescription;
	sid.defaultFile.t = destfile;
	sid.iDefaultIndex = -mask->iIconIndex;
	mask->hIcolibItem = IcoLib_AddIcon(&sid);
}
Пример #12
0
//フォルダ内ファイル(ディレクトリは除く)を再帰検索
bool UtilRecursiveEnumFile(LPCTSTR lpszRoot,std::list<CString> &rFileList)
{
	CFindFile cFindFile;
	TCHAR szPath[_MAX_PATH+1];
	_tcsncpy_s(szPath,lpszRoot,_MAX_PATH);
	PathAppend(szPath,_T("*"));

	BOOL bContinue=cFindFile.FindFile(szPath);
	while(bContinue){
		if(!cFindFile.IsDots()){
			if(cFindFile.IsDirectory()){
				UtilRecursiveEnumFile(cFindFile.GetFilePath(),rFileList);
			}else{
				rFileList.push_back(cFindFile.GetFilePath());
			}
		}
		bContinue=cFindFile.FindNextFile();
	}

	return !rFileList.empty();
}
Пример #13
0
int CVkProto::AuthRequest(MCONTACT hContact,const TCHAR* message)
{
	debugLogA("CVkProto::AuthRequest");
	if (!IsOnline())
		return 1;

	LONG userID = getDword(hContact, "ID", -1);
	if (userID == -1 || !hContact || userID == VK_FEED_USER)
		return 1;
	
	TCHAR msg[501] = {0};
	if (message)
		_tcsncpy_s(msg, 500, message, _TRUNCATE);

	Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.add.json", true, &CVkProto::OnReceiveAuthRequest)
		<< INT_PARAM("user_id", userID)
		<< TCHAR_PARAM("text", msg)
		<< VER_API)->pUserInfo = new CVkSendMsgParam(hContact);

	return 0;
}
Пример #14
0
/** an incoming file transfer has been offered */
void mwFileTransfer_offered(mwFileTransfer* ft)
{
	CSametimeProto* proto = getProtoFromMwFileTransfer(ft);
	proto->debugLog(_T("mwFileTransfer_offered() start"));

	const mwIdBlock* idb = mwFileTransfer_getUser(ft);
	MCONTACT hContact = proto->FindContactByUserId(idb->user);
	proto->debugLog(_T("Sametime mwFileTransfer_offered hContact=[%x]"), hContact);

	if (!hContact) {
		mwSametimeList* user_list = mwSametimeList_new();
		mwSametimeGroup* stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_NORMAL, Translate("None"));
		mwSametimeUser* stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, (mwIdBlock*)idb);
		hContact = proto->AddContact(stuser, (proto->options.add_contacts ? false : true));
	}

	proto->ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)ft, 0);

	TCHAR* filenameT = mir_utf8decodeT(mwFileTransfer_getFileName(ft));
	const char* message = mwFileTransfer_getMessage(ft);
	TCHAR descriptionT[512];
	if (message) {
		TCHAR* messageT = mir_utf8decodeT(message);
		mir_sntprintf(descriptionT, _T("%s - %s"), filenameT, messageT);
		mir_free(messageT);
	} else
		_tcsncpy_s(descriptionT, filenameT, _TRUNCATE);

	PROTORECVFILET pre = {0};
	pre.dwFlags = PRFF_TCHAR;
	pre.fileCount = 1;
	pre.timestamp = time(NULL);
	pre.descr.t = descriptionT;
	pre.files.t = &filenameT;
	pre.lParam = (LPARAM)ft;

	ProtoChainRecvFile(hContact, &pre);
	
	mir_free(filenameT);
}
Пример #15
0
CDataBase::CDataBase(const char* FileName)
{
	int len;
#ifdef UNICODE
	len = MultiByteToWideChar(CP_ACP, 0, FileName, -1, NULL, 0);
	m_FileName[0] = new TCHAR[len + 1];
	MultiByteToWideChar(CP_ACP, 0, FileName, -1, m_FileName[0], len + 1);
	m_FileName[0][len] = 0;
#else
	len = strlen(FileName);
	m_FileName[0] = new TCHAR[len + 1];
	strcpy_s(m_FileName[0], len + 1, FileName);
#endif

	TCHAR * tmp = _tcsrchr(m_FileName[0], '.');
	if (tmp)
	{
		m_FileName[1] = new TCHAR[len + 1];
		_tcsncpy_s(m_FileName[1], len + 1, m_FileName[0], tmp - m_FileName[0]);
		_tcscat_s(m_FileName[1], len + 1, _T(".pri"));
	} else {
		m_FileName[1] = new TCHAR[len + 5];
		_tcscpy_s(m_FileName[1], len + 5, m_FileName[0]);
		_tcscat_s(m_FileName[1], len + 5, _T(".pri"));
	}

	m_Opened = false;

	for (int i = 0; i < DBFileMax; ++i)
	{
		m_BlockManager[i] = NULL;
		m_FileAccess[i] = NULL;
		m_EncryptionManager[i] = NULL;
		m_HeaderBlock[i] = 0;
	}

	m_Entities = NULL;
	m_Settings = NULL;
	m_Events   = NULL;
}
Пример #16
0
extern "C" int __declspec(dllexport) Load(void)
{
	hMsftedit = LoadLibrary(_T("Msftedit.dll"));
	if (hMsftedit == NULL)
		return 1;

	clsdates = db_get_b(NULL, PluginName, "ClassicDates", 1) != 0;
	dtsubfldr = db_get_b(NULL, PluginName, "SubFolders", 1) != 0;
	catchcrashes = db_get_b(NULL, PluginName, "CatchCrashes", 1) != 0;

	mir_getLP(&pluginInfoEx);

	profname = Utils_ReplaceVarsT(_T("%miranda_profilename%.dat"));
	profpath = Utils_ReplaceVarsT(_T("%miranda_userdata%"));
	if (catchcrashes && !needrestart)
		mir_sntprintf(CrashLogFolder, TEXT("%s\\CrashLog"), profpath);
	_tcsncpy_s(VersionInfoFolder, profpath, _TRUNCATE);


	HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
	HookEvent(ME_OPT_INITIALISE, OptionsInit);
	HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);

	packlcid = (LCID)Langpack_GetDefaultLocale();

	InitIcons();

	if (catchcrashes && !needrestart)
		InitExceptionHandler();

	CreateServiceFunction(MS_CRASHDUMPER_STORETOFILE, StoreVersionInfoToFile);
	CreateServiceFunction(MS_CRASHDUMPER_STORETOCLIP, StoreVersionInfoToClipboard);
	CreateServiceFunction(MS_CRASHDUMPER_VIEWINFO, ViewVersionInfo);
	CreateServiceFunction(MS_CRASHDUMPER_GETINFO, GetVersionInfo);
	CreateServiceFunction(MS_CRASHDUMPER_UPLOAD, UploadVersionInfo);
	CreateServiceFunction(MS_CRASHDUMPER_URL, OpenUrl);
	CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceModeLaunch);
	CreateServiceFunction(MS_CRASHDUMPER_URLTOCLIP, CopyLinkToClipboard);
	return 0;
}
Пример #17
0
void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOOL patchVars)
{
	TCHAR tszTemp[MAX_PATH];

	ptrT tszRecvPath(db_get_tsa(NULL, "SRFile", "RecvFilesDirAdv"));
	if (tszRecvPath)
		_tcsncpy_s(tszTemp, tszRecvPath, _TRUNCATE);
	else
		mir_sntprintf(tszTemp, _T("%%mydocuments%%\\%s\\%%userid%%"), TranslateT("My received files"));

	if (hContact) {
		hContact = db_mc_tryMeta(hContact);

		REPLACEVARSARRAY rvaVarsToReplace[4];
		rvaVarsToReplace[0].key.t = _T("nick");
		rvaVarsToReplace[0].value.t = mir_tstrdup((TCHAR *)pcli->pfnGetContactDisplayName(hContact, 0));
		rvaVarsToReplace[1].key.t = _T("userid");
		rvaVarsToReplace[1].value.t = GetContactID(hContact);
		rvaVarsToReplace[2].key.t = _T("proto");
		rvaVarsToReplace[2].value.t = mir_a2t(GetContactProto(hContact));
		rvaVarsToReplace[3].key.t = NULL;
		rvaVarsToReplace[3].value.t = NULL;
		for (int i = 0; i < (_countof(rvaVarsToReplace) - 1); i++)
			RemoveInvalidFilenameChars(rvaVarsToReplace[i].value.t);

		TCHAR *result = Utils_ReplaceVarsT(tszTemp, hContact, rvaVarsToReplace);
		if (result) {
			_tcsncpy(tszTemp, result, _countof(tszTemp));
			mir_free(result);
			for (int i = 0; i < (_countof(rvaVarsToReplace) - 1); i++)
				mir_free(rvaVarsToReplace[i].value.t);
		}
	}

	if (patchVars)
		patchDir(tszTemp, _countof(tszTemp));
	RemoveInvalidPathChars(tszTemp);
	mir_tstrncpy(szDir, tszTemp, cchDir);
}
Пример #18
0
CFont::CFont(INT Height, UINT Width, UINT Weight, UINT Style, UINT Charset, UINT OutputPrecision,
	UINT Quality, UINT PitchAndFamily, LPCTSTR pFaceName)
	:m_hFont(NULL)
{
	memset(&m_lf, 0, sizeof(m_lf));
	m_lf.lfHeight = Height;
	m_lf.lfWidth = Width;
	m_lf.lfWeight = Weight;
	m_lf.lfItalic = !!(Style & stItalic);
	m_lf.lfUnderline = !!(Style & stUnderline);
	m_lf.lfStrikeOut = !!(Style & stStrikeout);
	m_lf.lfCharSet = Charset;
	m_lf.lfOutPrecision = OutputPrecision;
	m_lf.lfQuality = Quality;
	m_lf.lfPitchAndFamily = PitchAndFamily;
	_tcsncpy_s(m_lf.lfFaceName, pFaceName, LF_FACESIZE-1);

	for(unsigned clr=0; clr < 256; clr++)
	{
		m_bmiColors[clr].rgbBlue = m_bmiColors[clr].rgbGreen = m_bmiColors[clr].rgbRed = clr;
	}
}
Пример #19
0
char* CStringToNPStringCharacters(const CString &str)
{
	USES_CONVERSION;
	char* utf8str = NULL;
	int cnt = str.GetLength() + 1;
	TCHAR* tstr = new TCHAR[cnt];
	_tcsncpy_s(tstr, cnt, str, cnt);
	if (tstr != NULL)
	{
		LPWSTR wstr = T2W(tstr);

		// converts to utf8 string
		int nUTF8 = WideCharToMultiByte(CP_UTF8, 0, wstr, cnt, NULL, 0, NULL, NULL);
		if (nUTF8 > 0)
		{
			utf8str = (char *)NPN_MemAlloc(nUTF8);
			WideCharToMultiByte(CP_UTF8, 0, wstr, cnt, utf8str, nUTF8, NULL, NULL);
		}
		delete[] tstr;
	}
	return utf8str;
}
Пример #20
0
/*
 * create a system tray icon, create all necessary submenus
 */
void TSAPI CreateSystrayIcon(int create)
{
	NOTIFYICONDATA nim;

	nim.cbSize = sizeof(nim);
	nim.hWnd = PluginConfig.g_hwndHotkeyHandler;
	nim.uID = 100;
	nim.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
	nim.hIcon = PluginConfig.g_iconContainer;
	nim.uCallbackMessage = DM_TRAYICONNOTIFY;
	_tcsncpy_s(nim.szTip, _T("tabSRMM"), _TRUNCATE);
	if (create && !nen_options.bTrayExist) {
		Shell_NotifyIcon(NIM_ADD, &nim);
		nen_options.bTrayExist = TRUE;
		hIconTrayCurrent = 0;
		SetEvent(g_hEvent);
	}
	else if (create == FALSE && nen_options.bTrayExist) {
		Shell_NotifyIcon(NIM_DELETE, &nim);
		nen_options.bTrayExist = FALSE;
	}
}
Пример #21
0
unsigned int getWMPDisplayText( void* pWMPDisplayRaw, LPTSTR lpszStringBuf, int nMaxTextCount, int nDistrictId ) {
	hm_wmp_display* pWMPDisplay = ( hm_wmp_display* )pWMPDisplayRaw;
	hm_districtobj* pDistrictObj = NULL;
	hm_showobj* pShowObj = NULL;
	unsigned int uShowObjCount;
	hm_rs_uires_text* pUIResText = NULL;
	const hm_uires_text_data* pTextData = NULL;
	unsigned int uLenText = 0 ;
	unsigned int uLenTextDoCopy = 0;

	if ( pWMPDisplay->getDistrictObj( nDistrictId, &pDistrictObj ) ) {
		uShowObjCount = pDistrictObj->getShowObjCount();
		for ( unsigned int uShowObjIndex = 0; uShowObjIndex < uShowObjCount; ++uShowObjIndex ) {
			pShowObj = pDistrictObj->getShowObj( uShowObjIndex );
			if ( !pShowObj ) 
				continue;
			pUIResText = dynamic_cast<hm_rs_uires_text*>( pShowObj->m_pUIRes );
			if ( !pUIResText )
				continue;
			pTextData = pUIResText->getData();
			if ( pTextData ) {
				uLenText = pTextData->m_tstrData.length();
				if ( !lpszStringBuf ) {
					return uLenText + 1; // return the charicter count of buffer need.
				} else {
					if ( nMaxTextCount == 0 )
						return 0; // it specify no buffer.
					uLenTextDoCopy = ( unsigned int )min( ( unsigned int )( nMaxTextCount - 1 ), uLenText );
					_tcsncpy_s( lpszStringBuf, nMaxTextCount, pTextData->m_tstrData.c_str(), uLenTextDoCopy );
					return uLenTextDoCopy;
				}
				assert( false );
			}
		}
	}
	
	return 0;
}
Пример #22
0
//Example: Say PATH="c:\bin;d:\win", resource dll name (szDllName) is "ToolUI.dll",
//		   user locale is 936, and the .exe calling LoadLocResDll is c:\MyTools\Tool.exe
//			Search order:
//			a) c:\MyTools\936\ToolUI.dll (exe path + user default UI lang)			   
//			b) c:\MyTools\1033 (same with eng)
//			c) c:\MyTools\*\ToolUI.dll (where * is sub folder).
//			d) c:\bin\936\ToolUI.dll (first in path)
//			e) c:\bin\1033\ToolUI.dll (first in path + eng)
//			f) c:\bin\*\ToolUI.dll
//			g) d:\win\936\ToolUI.dll  (second in path)
//			h) d:\win\1033\ToolUI.dll (second in path + eng)
//			i) d:\win\*\ToolUI.dll (second in path + eng)
//			j) if bExeDefaultModule and not found, return exe HINSTANCE.
//			Note: The primary lang (without the sublang) is tested after the user ui lang.
// Main Input: szDllName - the name of the resource dll <ToolName>ui.dll. Ex: vcdeployUI.dll
// Main Output: HMODULE of resource dll or NULL - if not found (see bExeDefaultModule).
HMODULE LoadLocResDll(LPCTSTR szDllName,BOOL bExeDefaultModule=TRUE,DWORD dwExFlags=LOAD_LIBRARY_AS_DATAFILE,LPTSTR pszPathOut = NULL,size_t sizeInCharacters = 0  )
{
    HMODULE hmod = NULL;
    TCHAR driverpath[_MAX_PATH + 1], exepath[_MAX_PATH + 1];
    LPTSTR p = NULL;
    
    GetModuleFileName(GetModuleHandle(NULL), driverpath, _MAX_PATH);
	 // from MSDN: If the length of the path exceeds the size specified by the nSize parameter, the function succeeds and the string is truncated to nSize characters and may not be null terminated.
	 driverpath[_MAX_PATH] = '\0';

    // find path of tool
    p = driverpath + _TCSNLEN(driverpath, _MAX_PATH-1)-1;
    while ( *p != L'\\' && p != driverpath)
	{
        p--;
	}
    *p = '\0';

    LoadUILibrary(driverpath, szDllName, dwExFlags, 
                  &hmod, exepath,_countof(exepath), NULL);

    if ( hmod == NULL ) 
	{
        // search PATH\<lcid> for <ToolName>ui.dll
        hmod = LoadSearchPath(szDllName,exepath,_countof(exepath));
    }

    if ( hmod && pszPathOut )
	{
        _tcsncpy_s(pszPathOut,sizeInCharacters, exepath, _MAX_PATH-1);
	}
	//Not found dll, return the exe HINSTANCE as a fallback.
	if (hmod == NULL && bExeDefaultModule)
	{
		hmod=GetModuleHandle(NULL);
	}
    return hmod;
}
Пример #23
0
BOOL CClipboardHelper::Paste(HWND hWnd, LPTSTR lpszText, int nText)
{
#ifdef UNICODE
    if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
#else
    if (!IsClipboardFormatAvailable(CF_TEXT))
#endif
        return FALSE;

    if (!OpenClipboard(hWnd))
        return FALSE;

#ifdef UNICODE
    HGLOBAL hglbPaste = GetClipboardData(CF_UNICODETEXT);
#else
    HGLOBAL hglbPaste = GetClipboardData(CF_TEXT);
#endif
    if (hglbPaste == NULL)
    {
        CloseClipboard();
        return FALSE;
    }

    LPCTSTR lpszPaste = (LPCTSTR)GlobalLock(hglbPaste);
    if (lpszPaste == NULL)
    {
        CloseClipboard();
        return FALSE;
    }

    _tcsncpy_s(lpszText, nText, lpszPaste, _TRUNCATE);

    GlobalUnlock(hglbPaste);

    CloseClipboard();

    return TRUE;
}
// CMSOmniProvRowset :: CheckTable
// Finds if the table in the Query exists or not...
// 2.0
// Code to recognize table name enclosed in [ ]...
BOOL CMSOmniProvRowset::CheckTable(TCHAR* szTblNm)
{
	CMSOmniProvRowset* pT = (CMSOmniProvRowset*) this;
	if(szTblNm[0] == '[')
	{
		size_t iLenBuff = 0;
		iLenBuff = _tcslen(szTblNm);
		TCHAR *szTmpBuff= (TCHAR *) malloc(sizeof(TCHAR) *iLenBuff );
		 _tcsncpy_s(szTmpBuff, iLenBuff, szTblNm + 1,iLenBuff -2);

		if (!_tcscmp(pT->m_DBFile.m_szTblNm, szTmpBuff))
		{
		    free(szTmpBuff);
			return true;									
		}
		else
		    free(szTmpBuff);
	}
	if (!_tcscmp(pT->m_DBFile.m_szTblNm, szTblNm))
		return true;
	else 
		return false;
}
Пример #25
0
//UtilExpandTemplateString()のパラメータ展開に必要な情報を構築する
void MakeExpandInformationEx(std::map<stdString,CString> &envInfo,LPCTSTR lpOpenDir,LPCTSTR lpOutputFile)
{
	//環境変数で構築
	UtilMakeExpandInformation(envInfo);

	//変数登録
	if(lpOpenDir){
		envInfo[_T("dir")]=lpOpenDir;
		envInfo[_T("OutputDir")]=lpOpenDir;

		//出力ドライブ名
		TCHAR szBuffer[MAX_PATH+1];
		_tcsncpy_s(szBuffer,lpOpenDir,COUNTOF(szBuffer)-1);
		PathStripToRoot(szBuffer);
		if(szBuffer[_tcslen(szBuffer)-1]==L'\\')szBuffer[_tcslen(szBuffer)-1]=L'\0';
		envInfo[_T("OutputDrive")]=(LPCTSTR)szBuffer;
	}

	if(lpOutputFile){
		envInfo[_T("OutputFile")]=lpOutputFile;
		envInfo[_T("OutputFileName")]=PathFindFileName(lpOutputFile);
	}
}
Пример #26
0
   bool 
   FileUtilities::DeleteDirectory(const String &sDirName)
   {
      TCHAR szSource[MAX_PATH + 2] = _T("");
      _tcsncpy_s(szSource, MAX_PATH + 2, sDirName, MAX_PATH);

      // szSource should be double null terminated. Otherwise it won't
      // work. At least not when using Unicode.
      szSource[sDirName.GetLength()+1] = 0;

      SHFILEOPSTRUCT fs;
      ::memset(&fs, 0, sizeof(SHFILEOPSTRUCT));

      fs.pFrom = szSource;
      fs.wFunc = FO_DELETE;
      fs.fFlags |= (FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SILENT |FOF_NOERRORUI);

      int iResult = ::SHFileOperation(&fs);
      if (iResult != 0)
         return false;

      return true;
   }
Пример #27
0
void LoadMsgDlgFont(int i, LOGFONT *lf, COLORREF *colour)
{
	char str[32];
	int style;
	FontOptionsList &FO = fontOptionsList[i];

	if (colour) {
		mir_snprintf(str, SIZEOF(str), "Font%dCol", i);
		*colour = db_get_dw(NULL, CHATFONT_MODULE, str, FO.defColour);
	}
	if (lf) {
		mir_snprintf(str, SIZEOF(str), "Font%dSize", i);
		lf->lfHeight = (char)db_get_b(NULL, CHATFONT_MODULE, str, FO.defSize);
		lf->lfWidth = 0;
		lf->lfEscapement = 0;
		lf->lfOrientation = 0;
		mir_snprintf(str, SIZEOF(str), "Font%dSty", i);
		style = db_get_b(NULL, CHATFONT_MODULE, str, FO.defStyle);
		lf->lfWeight = style & FONTF_BOLD ? FW_BOLD : FW_NORMAL;
		lf->lfItalic = style & FONTF_ITALIC ? 1 : 0;
		lf->lfUnderline = 0;
		lf->lfStrikeOut = 0;
		mir_snprintf(str, SIZEOF(str), "Font%dSet", i);
		lf->lfCharSet = db_get_b(NULL, CHATFONT_MODULE, str, FO.defCharset);
		lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
		lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
		lf->lfQuality = DEFAULT_QUALITY;
		lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
		mir_snprintf(str, SIZEOF(str), "Font%d", i);

		ptrT tszFace(db_get_tsa(NULL, CHATFONT_MODULE, str));
		if (tszFace == NULL)
			lstrcpy(lf->lfFaceName, FO.szDefFace);
		else
			_tcsncpy_s(lf->lfFaceName, SIZEOF(lf->lfFaceName), tszFace, _TRUNCATE);
	}
}
Пример #28
0
int RotateBackups(TCHAR *backupfolder, TCHAR *dbname)
{
    backupFile *bf = NULL, *bftmp;
    HANDLE hFind;
    TCHAR backupfolderTmp[MAX_PATH];
    WIN32_FIND_DATA FindFileData;

    if (options.num_backups == 0)
        return 0; /* Roration disabled. */
    mir_sntprintf(backupfolderTmp, _T("%s\\%s*"), backupfolder, dbname);
    hFind = FindFirstFile(backupfolderTmp, &FindFileData);
    if (hFind == INVALID_HANDLE_VALUE)
        return 0;

    int i = 0;
    do {
        if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            continue;
        bftmp = (backupFile*)mir_realloc(bf, ((i + 1) * sizeof(backupFile)));
        if (bftmp == NULL)
            goto err_out;
        bf = bftmp;
        _tcsncpy_s(bf[i].Name, FindFileData.cFileName, _TRUNCATE);
        bf[i].CreationTime = FindFileData.ftCreationTime;
        i ++;
    } while (FindNextFile(hFind, &FindFileData));
    if (i > 0)
        qsort(bf, i, sizeof(backupFile), Comp); /* Sort the list of found files by date in descending order. */
    for (; i >= options.num_backups; i --) {
        mir_sntprintf(backupfolderTmp, _T("%s\\%s"), backupfolder, bf[(i - 1)].Name);
        DeleteFile(backupfolderTmp);
    }
err_out:
    FindClose(hFind);
    mir_free(bf);
    return 0;
}
Пример #29
0
	void CheckRun()
	{
		m_btnOk.Enable(m_profileList.GetSelectedCount() == 1);

		TCHAR profile[MAX_PATH];
		LVITEM item = { 0 };
		item.mask = LVIF_TEXT | LVIF_IMAGE;
		item.iItem = m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL);
		item.pszText = profile;
		item.cchTextMax = _countof(profile);
		if (!m_profileList.GetItem(&item))
			return;

		switch(item.iImage) {
		case 3:
			m_btnOk.Enable(false);
			return;

		case 2:
			m_btnOk.SetText(TranslateT("&Convert"));
			m_pd->bRun = false;
			break;

		default:
			m_btnOk.SetText(TranslateT("&Run"));
			m_pd->bRun = true;
		}

		// profile is placed in "profile_name" subfolder

		TCHAR tmpPath[MAX_PATH];
		mir_sntprintf(tmpPath, _countof(tmpPath), _T("%s\\%s.dat"), m_pd->ptszProfileDir, profile);
		if (_taccess(tmpPath, 2))
			mir_sntprintf(m_pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profile, profile);
		else
			_tcsncpy_s(m_pd->ptszProfile, MAX_PATH, tmpPath, _TRUNCATE);
	}
Пример #30
0
/**
 * Function to enumerate all drives on the system and then recurse it.
 *
 * @see RecurseFileSystem()
 *
 * @author Jacob Hammack
 */
static void EnumerateFiles()
{
	TCHAR DriveLetter[MAX_PATH];
	TCHAR *pch;
	GetLogicalDriveStrings(MAX_PATH, DriveLetter);
	pch = DriveLetter;

	while (*pch) 
	{
		if(*pch == 0)
		{
			break;
		}

		if(GetDriveType(pch) == DRIVE_FIXED)
		{
			TCHAR tmp[MAX_PATH];
			_tcsncpy_s(tmp, _tcslen(pch), pch, lstrlen(pch) -1);
			RecurseFileSystem(tmp);
		}

		pch = &pch[lstrlen(pch) + 1];
	}	
}