Esempio n. 1
0
File: icon.c Progetto: jsoref/rufus
/*
 * Create an autorun.inf, if none exists
 * We use this to set the icon as well as labels that are longer than 11/32 chars or,
 * in the case of FAT, contain non-English characters
 */
BOOL SetAutorun(const char* path)
{
	FILE* fd;
	char filename[64];
	wchar_t wlabel[128], wRufusVersion[32];

	safe_sprintf(filename, sizeof(filename), "%s\\autorun.inf", path);
	fd = fopen(filename, "r");	// If there's an existing autorun, don't overwrite
	if (fd != NULL) {
		uprintf("%s already exists - keeping it\n", filename);
		fclose(fd);
		return FALSE;
	}
	// No "/autorun.inf" => create a new one in UTF-16 LE mode
	fd = fopen(filename, "w, ccs=UTF-16LE");
	if (fd == NULL) {
		uprintf("Unable to create %s\n", filename);
		return FALSE;
	}

	GetWindowTextW(hLabel, wlabel, ARRAYSIZE(wlabel));
	GetWindowTextW(hMainDialog, wRufusVersion, ARRAYSIZE(wRufusVersion));
	fwprintf(fd, L"; Created by %s\n; " LTEXT(RUFUS_URL) L"\n", wRufusVersion);
	fwprintf(fd, L"[autorun]\nicon  = autorun.ico\nlabel = %s\n", wlabel);
	fclose(fd);
	uprintf("Created: %s\n", filename);

	// .inf -> .ico
	filename[strlen(filename)-1] = 'o';
	filename[strlen(filename)-2] = 'c';
	return SaveIcon(filename);
}
//	@date 2002.2.17 YAZAKI CShareDataのインスタンスは、CProcessにひとつあるのみ。
CFuncKeyWnd::CFuncKeyWnd()
: CWnd(_T("::CFuncKeyWnd"))
{
	int		i;
	LOGFONT	lf;
	m_pcEditDoc = NULL;
	/* 共有データ構造体のアドレスを返す */
	m_pShareData = &GetDllShareData();
	m_nCurrentKeyState = -1;
	for( i = 0; i < _countof(m_szFuncNameArr); ++i ){
		m_szFuncNameArr[i][0] = LTEXT('\0');
	}
//	2002.11.04 Moca Open()側で設定
//	m_nButtonGroupNum = 4;

	for( i = 0; i < _countof( m_hwndButtonArr ); ++i ){
		m_hwndButtonArr[i] = NULL;
	}

	/* 表示用フォント */
	/* LOGFONTの初期化 */
	memset_raw( &lf, 0, sizeof(lf) );
	lf.lfHeight			= DpiPointsToPixels(-9);	// 2009.10.01 ryoji 高DPI対応(ポイント数から算出)
	lf.lfWidth			= 0;
	lf.lfEscapement		= 0;
	lf.lfOrientation	= 0;
	lf.lfWeight			= 400;
	lf.lfItalic			= 0x0;
	lf.lfUnderline		= 0x0;
	lf.lfStrikeOut		= 0x0;
	lf.lfCharSet		= 0x80;
	lf.lfOutPrecision	= 0x3;
	lf.lfClipPrecision	= 0x2;
	lf.lfQuality		= 0x1;
	lf.lfPitchAndFamily	= 0x31;
	_tcscpy( lf.lfFaceName, _T("MS Pゴシック") );
	m_hFont = ::CreateFontIndirect( &lf );

	m_bSizeBox = false;
	m_hwndSizeBox = NULL;
	m_nTimerCount = 0;

	return;
}
// WM_TIMERタイマーの処理
LRESULT CFuncKeyWnd::OnTimer( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
// 	HWND hwnd,	// handle of window for timer messages
//	UINT uMsg,	// WM_TIMER message
//	UINT idEvent,	// timer identifier
//	DWORD dwTime 	// current system time


	//	return;
	if( NULL == GetHwnd() ){
		return 0;
	}

	if( ::GetActiveWindow() != GetParentHwnd() && m_nCurrentKeyState != -1 ) {	//	2002/06/02 MIK	// 2006.12.20 ryoji 初回更新は処理する
		return 0;
	}

	int			nIdx;
//	int			nFuncId;
	int			i;

// novice 2004/10/10
	/* Shift,Ctrl,Altキーが押されていたか */
	nIdx = getCtrlKeyState();
	/* ALT,Shift,Ctrlキーの状態が変化したか */
	if( nIdx != m_nCurrentKeyState ){
		m_nTimerCount = TIMER_CHECKFUNCENABLE + 1;

		/* ファンクションキーの機能名を取得 */
		for( i = 0; i < _countof( m_szFuncNameArr ); ++i ){
			// 2007.02.22 ryoji CKeyBind::GetFuncCode()を使う
			EFunctionCode	nFuncCode = CKeyBind::GetFuncCode(
					(WORD)(((VK_F1 + i) | ((WORD)((BYTE)(nIdx))) << 8)),
					m_pShareData->m_Common.m_sKeyBind.m_nKeyNameArrNum,
					m_pShareData->m_Common.m_sKeyBind.m_pKeyNameArr
			);
			if( nFuncCode != m_nFuncCodeArr[i] ){
				m_nFuncCodeArr[i] = nFuncCode;
				if( 0 == m_nFuncCodeArr[i] ){
					m_szFuncNameArr[i][0] = LTEXT('\0');
				}else{
					//	Oct. 2, 2001 genta
					m_pcEditDoc->m_cFuncLookup.Funccode2Name(
						m_nFuncCodeArr[i],
						m_szFuncNameArr[i],
						_countof(m_szFuncNameArr[i]) - 1
					);
				}
				Wnd_SetText( m_hwndButtonArr[i], m_szFuncNameArr[i] );
			}
		}
	}
	m_nTimerCount += TIMER_TIMEOUT;
	if( m_nTimerCount > TIMER_CHECKFUNCENABLE ||
		nIdx != m_nCurrentKeyState
	){
		m_nTimerCount = 0;
		/* 機能が利用可能か調べる */
		for( i = 0; i < _countof(	m_szFuncNameArr ); ++i ){
			if( IsFuncEnable( (CEditDoc*)m_pcEditDoc, m_pShareData, m_nFuncCodeArr[i]  ) ){
				::EnableWindow( m_hwndButtonArr[i], TRUE );
			}else{
				::EnableWindow( m_hwndButtonArr[i], FALSE );
			}
		}
	}
	m_nCurrentKeyState = nIdx;
	return 0;
}
/*!	バックアップファイルの詳細設定エディットボックスを適切に更新する

	@date 2005.11.07 aroka 新規追加

	@note 詳細設定切り替え時のデフォルトをオプションに合わせるため、
		m_szBackUpPathAdvanced を更新する
*/
void CPropBackup::UpdateBackupFile(HWND hwndDlg)	//	バックアップファイルの詳細設定
{
	wchar_t temp[MAX_PATH];
	/* バックアップを作成するファイル */ // 20051107 aroka
	if( !m_Common.m_sBackup.m_bBackUp ){
		temp[0] = LTEXT('\0');
	}
	else{
		if( m_Common.m_sBackup.m_bBackUpFolder ){
			temp[0] = LTEXT('\0');
		}
		else if( m_Common.m_sBackup.m_bBackUpDustBox  ){
			auto_sprintf( temp, LTEXT("%ls\\"), LSW(STR_PROPCOMBK_DUSTBOX) );
		}
		else{
			auto_sprintf( temp, LTEXT(".\\") );
		}

		switch( m_Common.m_sBackup.GetBackupType() ){
		case 1: // .bak
			wcscat( temp, LTEXT("$0.bak") );
			break;
		case 5: // .*.bak
			wcscat( temp, LTEXT("$0.*.bak") );
			break;
		case 3: // .b??
			wcscat( temp, LTEXT("$0.b??") );
			break;
		case 6: // .*.b??
			wcscat( temp, LTEXT("$0.*.b??") );
			break;
		case 2:	//	日付,時刻
		case 4:	//	日付,時刻
			wcscat( temp, LTEXT("$0_") );

			if( m_Common.m_sBackup.GetBackupOpt(BKUP_YEAR) ){	/* バックアップファイル名:日付の年 */
				wcscat( temp, LTEXT("%Y") );
			}
			if( m_Common.m_sBackup.GetBackupOpt(BKUP_MONTH) ){	/* バックアップファイル名:日付の月 */
				wcscat( temp, LTEXT("%m") );
			}
			if( m_Common.m_sBackup.GetBackupOpt(BKUP_DAY) ){	/* バックアップファイル名:日付の日 */
				wcscat( temp, LTEXT("%d") );
			}
			if( m_Common.m_sBackup.GetBackupOpt(BKUP_HOUR) ){	/* バックアップファイル名:日付の時 */
				wcscat( temp, LTEXT("%H") );
			}
			if( m_Common.m_sBackup.GetBackupOpt(BKUP_MIN) ){	/* バックアップファイル名:日付の分 */
				wcscat( temp, LTEXT("%M") );
			}
			if( m_Common.m_sBackup.GetBackupOpt(BKUP_SEC) ){	/* バックアップファイル名:日付の秒 */
				wcscat( temp, LTEXT("%S") );
			}

			wcscat( temp, LTEXT(".*") );
			break;
		default:
			break;
		}
	}
	if( !m_Common.m_sBackup.m_bBackUpPathAdvanced ){	// 詳細設定モードでないときだけ自動更新する
		auto_sprintf( m_Common.m_sBackup.m_szBackUpPathAdvanced, _T("%ls"), temp );
		::DlgItem_SetText( hwndDlg, IDC_EDIT_BACKUPFILE, m_Common.m_sBackup.m_szBackUpPathAdvanced );
	}
	return;
}
/*!
	@return 機能が割り当てられているキーストロークの数
	
	@date Oct. 31, 2001 genta 動的な機能名に対応するため引数追加
	@date 2007.02.22 ryoji デフォルト機能割り当てに関する処理を追加
*/
int CKeyBind::CreateKeyBindList(
	HINSTANCE		hInstance,		//!< [in] インスタンスハンドル
	int				nKeyNameArrNum,	//!< [in]
	KEYDATA*		pKeyNameArr,	//!< [out]
	CNativeW&		cMemList,		//!<
	CFuncLookup*	pcFuncLookup,	//!< [in] 機能番号→名前の対応を取る
	BOOL			bGetDefFuncCode //!< [in] ON:デフォルト機能割り当てを使う/OFF:使わない デフォルト:TRUE
)
{
	int		i;
	int		j;
	int		nValidKeys;
	WCHAR	pszStr[256];
	WCHAR	szFuncName[256];
	WCHAR	szFuncNameJapanese[256];

	nValidKeys = 0;
	cMemList.SetString(LTEXT(""));
	const WCHAR*	pszSHIFT = LTEXT("Shift+");
	const WCHAR*	pszCTRL  = LTEXT("Ctrl+");
	const WCHAR*	pszALT   = LTEXT("Alt+");
	const WCHAR*	pszTAB   = LTEXT("\t");
	const WCHAR*	pszCR    = LTEXT("\r\n");	//\r=0x0d=CRを追加


	cMemList.AppendString( LSW(STR_ERR_DLGKEYBIND1) );
	cMemList.AppendString( pszCR );
	cMemList.AppendString( LTEXT("-----\t-----\t-----\t-----\t-----") );
	cMemList.AppendString( pszCR );

	for( j = 0; j < 8; ++j ){
		for( i = 0; i < nKeyNameArrNum; ++i ){
			int iFunc = GetFuncCodeAt( pKeyNameArr[i], j, bGetDefFuncCode );

			if( 0 != iFunc ){
				nValidKeys++;
				if( j & _SHIFT ){
					cMemList.AppendString( pszSHIFT );
				}
				if( j & _CTRL ){
					cMemList.AppendString( pszCTRL );
				}
				if( j & _ALT ){
					cMemList.AppendString( pszALT );
				}
				cMemList.AppendString( to_wchar(pKeyNameArr[i].m_szKeyName) );
				//	Oct. 31, 2001 genta 
				if( !pcFuncLookup->Funccode2Name(
					iFunc,
					szFuncNameJapanese, 255 )){
					auto_strcpy( szFuncNameJapanese, LSW(STR_ERR_DLGKEYBIND2) );
				}
				szFuncName[0] = LTEXT('\0'); /*"---unknown()--"*/

//				/* 機能名日本語 */
//				::LoadString(
//					hInstance,
//					pKeyNameArr[i].m_nFuncCodeArr[j],
//					 szFuncNameJapanese, 255
//				);
				cMemList.AppendString( pszTAB );
				cMemList.AppendString( szFuncNameJapanese );

				/* 機能ID→関数名,機能名日本語 */
				//@@@ 2002.2.2 YAZAKI マクロをCSMacroMgrに統一
				CSMacroMgr::GetFuncInfoByID(
					hInstance,
					iFunc,
					szFuncName,
					szFuncNameJapanese
				);

				/* 関数名 */
				cMemList.AppendString( pszTAB );
				cMemList.AppendString( szFuncName );

				/* 機能番号 */
				cMemList.AppendString( pszTAB );
				auto_sprintf( pszStr, LTEXT("%d"), iFunc );
				cMemList.AppendString( pszStr );

				/* キーマクロに記録可能な機能かどうかを調べる */
				cMemList.AppendString( pszTAB );
				//@@@ 2002.2.2 YAZAKI マクロをCSMacroMgrに統一
				if( CSMacroMgr::CanFuncIsKeyMacro( iFunc ) ){
					cMemList.AppendString( LTEXT("○") );
				}else{
					cMemList.AppendString( LTEXT("×") );
				}



				cMemList.AppendString( pszCR );
			}
		}
	}
	return nValidKeys;
}