static void StatusBarCreateCdromTip(int part) { WCHAR tempTip[512]; WCHAR *szText; int id; int drive = sb_part_meanings[part] & 0xf; int bus = cdrom[drive].bus_type; id = IDS_5377 + (bus - 1); szText = plat_get_string(id); if (cdrom[drive].host_drive == 200) { if (wcslen(cdrom[drive].image_path) == 0) _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); else _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, cdrom[drive].image_path); } else _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 4); wcscpy(sbTips[part], tempTip); }
static void StatusBarCreateFloppyTip(int part) { WCHAR wtext[512]; WCHAR tempTip[512]; int drive = sb_part_meanings[part] & 0xf; mbstowcs(wtext, fdd_getname(fdd_get_type(drive)), strlen(fdd_getname(fdd_get_type(drive))) + 1); if (wcslen(floppyfns[drive]) == 0) { _swprintf(tempTip, plat_get_string(IDS_2117), drive+1, wtext, plat_get_string(IDS_2057)); } else { _swprintf(tempTip, plat_get_string(IDS_2117), drive+1, wtext, floppyfns[drive]); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); }
static void StatusBarCreateZIPTip(int part) { WCHAR tempTip[512]; WCHAR *szText; int id; int drive = sb_part_meanings[part] & 0xf; int bus = zip_drives[drive].bus_type; id = IDS_5377 + (bus - 1); szText = plat_get_string(id); int type = zip_drives[drive].is_250 ? 250 : 100; if (wcslen(zip_drives[drive].image_path) == 0) { _swprintf(tempTip, plat_get_string(IDS_2054), type, drive+1, szText, plat_get_string(IDS_2057)); } else { _swprintf(tempTip, plat_get_string(IDS_2054), type, drive+1, szText, zip_drives[drive].image_path); } if (sbTips[part] != NULL) { free(sbTips[part]); sbTips[part] = NULL; } sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); }
/* * Fix up the command line to call git.exe * We have to be very careful about quoting here so we just * trim off the first argument and replace it leaving the rest * untouched. */ static LPWSTR fixup_commandline(LPWSTR exepath, LPWSTR *exep, int *wait, LPWSTR prefix_args, int prefix_args_len, int is_git_command, int skip_arguments, int append_quote_to_cmdline) { int wargc = 0; LPWSTR cmd = NULL, cmdline = NULL; LPWSTR *wargv = NULL, p = NULL; cmdline = GetCommandLine(); wargv = CommandLineToArgvW(cmdline, &wargc); cmd = (LPWSTR)malloc(sizeof(WCHAR) * (wcslen(cmdline) + prefix_args_len + 1 + MAX_PATH + append_quote_to_cmdline)); if (prefix_args) { if (is_git_command) _swprintf(cmd, L"\"%s\\%s\" %.*s", exepath, L"git.exe", prefix_args_len, prefix_args); else _swprintf(cmd, L"%.*s", prefix_args_len, prefix_args); } else wcscpy(cmd, L"git.exe"); /* skip wargv[0], append the remaining arguments */ ++skip_arguments; if (skip_arguments < wargc) { int i; for (i = 0, p = cmdline; p && *p && i < skip_arguments; i++) { if (i) while (isspace(*p)) p++; if (*p == L'"') p++; p += wcslen(wargv[i]); if (*p == L'"') p++; while (*p && !isspace(*p)) p++; } wcscat(cmd, p); } if (append_quote_to_cmdline) wcscat(cmd, L"\""); if (wargc > 1 && !wcscmp(wargv[1], L"gui")) *wait = 0; LocalFree(wargv); return cmd; }
static BOOL EchoIncomingPackets(SOCKET sock) { CHAR readBuffer[RECV_BUF]; WCHAR logBuf[256]; INT totalSentBytes; INT readBytes; INT retVal; do { readBytes = recv(sock, readBuffer, RECV_BUF, 0); if (readBytes > 0) { _swprintf(logBuf, L"Received %d bytes from client", readBytes); LogEvent(logBuf, 0, 0, LOG_FILE); totalSentBytes = 0; while (!bShutdown && totalSentBytes < readBytes) { retVal = send(sock, readBuffer + totalSentBytes, readBytes - totalSentBytes, 0); if (retVal > 0) { _swprintf(logBuf, L"Sent %d bytes back to client", retVal); LogEvent(logBuf, 0, 0, LOG_FILE); totalSentBytes += retVal; } else if (retVal == SOCKET_ERROR) { LogEvent(L"Echo: socket error", WSAGetLastError(), 0, LOG_ERROR); return FALSE; } else { /* Client closed connection before we could reply to all the data it sent, so quit early. */ LogEvent(L"Peer unexpectedly dropped connection!", 0, 0, LOG_FILE); return FALSE; } } } else if (readBytes == SOCKET_ERROR) { LogEvent(L"Echo: socket error", WSAGetLastError(), 0, LOG_ERROR); return FALSE; } } while ((readBytes != 0) && (!bShutdown)); if (!bShutdown) LogEvent(L"Echo: Connection closed by peer", 0, 0, LOG_FILE); return TRUE; }
wstring Player::toString() const { wstring res = L"Player "; wchar_t buff[6]; _swprintf(buff, 5, L"%d\n", m_id); res += wstring(buff); res += m_history.toString() + L"\n"; res += L"score "; _swprintf(buff, 5, L"%d\n", getTotalScore()); res += wstring(buff); return res; }
//----------------------------------------------- void SJ_Menu_Begin( char lastState ) { g_timeToNextKey = 0.5f;//s_keyTime*0.5f; ZeroMemory( s_availSkins, sizeof(s_availSkins) ); s_curSkin = 0; // -- Retrieve all available skins wchar_t path[MAX_PATH]; GetCurrentDirectory(MAX_PATH-1, path); _swprintf( g_txt, L"%s\\*", path ); #ifdef _WIN64 PVOID OldValue = NULL; Wow64DisableWow64FsRedirection( &OldValue ); #endif WIN32_FIND_DATA ffdata; HANDLE hFind = FindFirstFile( g_txt, &ffdata ); if ( hFind != INVALID_HANDLE_VALUE ) { do { if ( ffdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { static const wchar_t* keypaths[] = { L"config.txt", L"levels", L"levels\\easy", L"levels\\medium", L"levels\\hard", L"levels\\extreme", L"sprites" }; bool validSkin = true; for ( int i = 0; i < 7 && validSkin; ++i ) { _swprintf( g_txt, L"%s\\%s\\%s", path, ffdata.cFileName, keypaths[i] ); validSkin = validSkin && _waccess_s( g_txt, 0 ) == 0; } if ( validSkin && s_curSkin < MAX_AVAILSKINS ) { wcscpy_s( s_availSkins[s_curSkin], ffdata.cFileName ); if ( _wcsicmp( ffdata.cFileName, DEFAULT_SKIN ) == 0 ) s_skinValue = s_curSkin; ++s_curSkin; } }else { } }while ( FindNextFile(hFind,&ffdata)!=0 ); FindClose(hFind); } #ifdef _WIN64 if ( OldValue ) Wow64RevertWow64FsRedirection( OldValue ); #endif Menu_UpdateLabels(); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_UPDATECAREPOS: { WCHAR sz[1024]; LPCWSTR lpszString = (LPCWSTR)lParam; _swprintf(sz, L"%s", lpszString); SetWindowTextW(hWndEdit, sz); break; } case WM_PAINT: { RECT rect; GetClientRect(hWnd, &rect); PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); DrawText(hdc, _T("Open Chrome Browser and observe the text box"), 49, &rect, DT_CENTER|DT_WORDBREAK); EndPaint(hWnd, &ps); break; } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
static BOOL RecieveIncomingPackets(SOCKET sock) { CHAR readBuffer[BUFSIZE]; INT readBytes; do { readBytes = recv(sock, readBuffer, BUFSIZE, 0); if (readBytes > 0) { TCHAR logBuf[256]; _swprintf(logBuf, L"Discard: Received %d bytes from client", readBytes); LogEvent(logBuf, 0, 0, LOG_FILE); } else if (readBytes == SOCKET_ERROR) { LogEvent(L"Discard: Socket Error", WSAGetLastError(), 0, LOG_ERROR); return FALSE; } } while ((readBytes > 0) && (!bShutdown)); if (!bShutdown) LogEvent(L"Discard: Connection closed by peer", 0, 0, LOG_FILE); return TRUE; }
tvector<tstring> ListDirectory(const tstring& sDirectory, bool bDirectories) { tvector<tstring> asResult; wchar_t szPath[MAX_PATH]; _swprintf(szPath, L"%s\\*", convert_to_wstring(sDirectory).c_str()); WIN32_FIND_DATA fd; HANDLE hFind = FindFirstFile(szPath, &fd); if (hFind != INVALID_HANDLE_VALUE) { int count = 0; do { if (!bDirectories && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) continue; // Duh. if (wcscmp(fd.cFileName, L".") == 0 || wcscmp(fd.cFileName, L"..") == 0) continue; asResult.push_back(convert_from_wstring(fd.cFileName)); } while(FindNextFile(hFind, &fd)); FindClose(hFind); } return asResult; }
void Display(char* fmt,...) { const size_t size = 1024; char buf[size]; va_list ap; va_start(ap, fmt); int n = vsnprintf(buf, size, fmt, ap); va_end(ap); DWORD nCharsWritten; char fullbuf[size]; sprintf(fullbuf, "%*s", depth, ""); strcat(fullbuf, buf); FILE* f = fopen("c:\\dart_bleeding\\trace.log", "a+"); fprintf(f, "%s", fullbuf); fclose(f); va_end(ap); // WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), fullbuf, strlen(fullbuf), &nCharsWritten, NULL); return; WCHAR wfullbuf[size]; _swprintf(wfullbuf, _T("%*s"), depth, _T("")); WCHAR wbuf[size]; mbstowcs(wbuf, buf, strlen(buf)); wbuf[strlen(buf)] = L'\0'; wcscat(wfullbuf, wbuf); //WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), wfullbuf, wcslen(wfullbuf), &nCharsWritten, NULL); //wprintf(wfullbuf); //WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), wfullbuf, wcslen(wfullbuf),&nCharsWritten,NULL); }
static void StatusBarCreateSoundTip(int part) { WCHAR tempTip[512]; _swprintf(tempTip, plat_get_string(IDS_2068)); if (sbTips[part] != NULL) free(sbTips[part]); sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); }
static VOID OnResolutionChanged(PINFO pInfo, INT position) { WCHAR Buffer[64]; INT MaxSlider; MaxSlider = SendDlgItemMessageW(pInfo->hDisplayPage, IDC_GEOSLIDER, TBM_GETRANGEMAX, 0, 0); if (position == MaxSlider) { LoadStringW(hInst, IDS_FULLSCREEN, Buffer, sizeof(Buffer) / sizeof(WCHAR)); } else { WCHAR Pixel[64]; if (LoadStringW(hInst, IDS_PIXEL, Pixel, sizeof(Pixel) / sizeof(WCHAR))) { #ifdef _MSC_VER _swprintf(Buffer, Pixel, pInfo->DisplayDeviceList->Resolutions[position].dmPelsWidth, pInfo->DisplayDeviceList->Resolutions[position].dmPelsHeight, Pixel); #else swprintf(Buffer, Pixel, pInfo->DisplayDeviceList->Resolutions[position].dmPelsWidth, pInfo->DisplayDeviceList->Resolutions[position].dmPelsHeight, Pixel); #endif } } SendDlgItemMessageW(pInfo->hDisplayPage, IDC_SETTINGS_RESOLUTION_TEXT, WM_SETTEXT, 0, (LPARAM)Buffer); }
static void StatusBarCreateDiskTip(int part) { WCHAR tempTip[512]; WCHAR *szText; int id; int bus = sb_part_meanings[part] & 0xf; id = IDS_4352 + (bus - 1); szText = plat_get_string(id); _swprintf(tempTip, plat_get_string(IDS_4096), szText); if (sbTips[part] != NULL) free(sbTips[part]); sbTips[part] = (WCHAR *)malloc((wcslen(tempTip) << 1) + 2); wcscpy(sbTips[part], tempTip); }
static DWORD WINAPI SaveCrashDump( void *pExceptionInfo ) { HMODULE dbghelp=NULL; { wchar_t path[_MAX_PATH]; GetModuleFileName(NULL,path,_countof(path)); PathRemoveFileSpec(path); dbghelp=LoadLibrary(L"dbghelp.dll"); LPCTSTR szResult = NULL; typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam ); MINIDUMPWRITEDUMP dump=NULL; if (dbghelp) dump=(MINIDUMPWRITEDUMP)GetProcAddress(dbghelp,"MiniDumpWriteDump"); if (dump) { HANDLE file; for (int i=1;;i++) { wchar_t fname[_MAX_PATH]; _swprintf(fname,L"%s\\CS_Crash%d.dmp",path,i); file=CreateFile(fname,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL); if (file!=INVALID_HANDLE_VALUE || GetLastError()!=ERROR_FILE_EXISTS) break; } if (file!=INVALID_HANDLE_VALUE) { _MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = GetCurrentThreadId(); ExInfo.ExceptionPointers = (_EXCEPTION_POINTERS*)pExceptionInfo; ExInfo.ClientPointers = NULL; dump(GetCurrentProcess(),GetCurrentProcessId(),file,MiniDumpType,&ExInfo,NULL,NULL); CloseHandle(file); } } } if (dbghelp) FreeLibrary(dbghelp); TerminateProcess(GetCurrentProcess(),10); return 0; }
LRESULT CALLBACK WndProc( HWND window, UINT message, WPARAM wparam, LPARAM lparam ) { switch (message) { case WM_CLOSE: DestroyWindow(window); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_PAINT: { RECT rect; GetClientRect(window, &rect); int px = (rect.right - rect.left) / 2 + X; int py = (rect.bottom - rect.top) / 2 + Y; RECT fill; fill.left = px - 5; fill.right = px + 5; fill.top = py - 5; fill.bottom = py + 5; PAINTSTRUCT ps; HDC dc = BeginPaint(window, &ps); FillRect(dc, &fill, (GetKeyState(VK_SPACE) < 0) ? red : green); WCHAR text[100]; _swprintf(text, L"Frame: %d\nSimTime: %d\n", frameNumber, currentSimulationTime - previousSimulationTime); DrawTextW(dc, text, -1, &rect, DT_LEFT); EndPaint(window, &ps); return 0; } case WM_TIMER: simulate(); InvalidateRect(window, 0, TRUE); return 0; default: return DefWindowProc(window, message, wparam, lparam); } }
//----------------------------------------------- void SJ_Menu_Render( ) { RECT r={0}; r.top = 10; r.left = 10; g_pFont->DrawTextW( g_pSprite, SJ_GAME_NAME L" " SJ_VERSION, -1, &r, DT_NOCLIP, 0xffffffff ); r.top = LONG(g_clRect.bottom/2 - (s_nEntries*20.0f)/2.0f ); const sMenuEntry* me = NULL; for ( int i = 0; i < s_nEntries; ++i ) { me = s_menuEntries+i; _swprintf( g_txt, s_curEntry==i?L"< %s %s >":L"%s %s", me->menuLabel, me->menuValue ); g_pFont->DrawTextW( g_pSprite, g_txt, -1, &r, DT_CALCRECT, 0 ); r.left = LONG( g_clRect.right/2.0f - (r.right-r.left)/2.0f ); if ( s_curEntry == i ) r.left += LONG(sinf(g_states[g_curState].acumTime*10.0f)*2.0f); g_pFont->DrawTextW( g_pSprite, g_txt, -1, &r, DT_NOCLIP, s_curEntry==i?s_cSelected:s_cNormal ); r.top += 20; } r.top = g_clRect.bottom - 20; r.left = 10; g_pFont->DrawTextW( g_pSprite, SJ_AUTHOR, -1, &r, DT_NOCLIP, 0x44ffffff ); g_pSprite->Draw( g_pTextures[ IDT_BLOCK ], NULL, NULL, &D3DXVECTOR3( g_clRect.right*0.75f - g_blDim[0]/2.0f, g_clRect.bottom*0.25f - g_blDim[1]/2.0f, 0.0f ), 0xffffffff ); }
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ // Name : マップデータロード // Description : 任意のマップデータをロードする // Arguments : id / ステージID // Returns : 成否(true:成功) //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ bool CMapData::LoadData(int id) { // ----- 初期化処理 m_pFieldBlock.clear(); m_pLayoutBlock.clear(); m_pLayoutObject.clear(); // ----- マップデータ読み込み std::ifstream ifs(MAPDATA_LIST[id]); if (ifs.fail()) { #ifdef _DEBUG_MESSAGEBOX LPTSTR str = new TCHAR[256]; _swprintf(str, _T("MapData::Load map data error! stage ID %d."), id); MessageBox(NULL, str, _T("error"), MB_OK | MB_ICONERROR); delete[] str; #endif return false; } std::istreambuf_iterator<char> it(ifs); std::istreambuf_iterator<char> last; std::string str(it, last); // ----- マップデータ登録 // 登録準備 std::stringstream ss(str); std::string tmp; // 開始位置読み込み getline(ss, tmp, ','); // X座標登録 m_startPoint.x = stof(tmp); getline(ss, tmp, ','); // Y座標登録 m_startPoint.y = stof(tmp); getline(ss, tmp); // 改行をスキップ // 左右壁位置読み込み getline(ss, tmp, ','); // 左壁のX座標登録 m_leftWallX = stof(tmp); getline(ss, tmp, ','); // 右壁のX座標登録 m_rightWallX = stof(tmp); getline(ss, tmp); // 改行をスキップ // 上下壁位置読み込み getline(ss, tmp, ','); // 上壁のY座標登録 m_topWallY = stof(tmp); getline(ss, tmp, ','); // 下壁のY座標登録 m_bottomWallY = stof(tmp); getline(ss, tmp); // 改行をスキップ // フィールドブロックのデータ読み込み CCharacter* pObj = NULL; CFieldBlock* pFBlock = NULL; int eid = 0; int prevBid = -1; int cnt = 0; float width = 0.0f; float height = 0.0f; D3DXVECTOR3 color(0.0f, 0.0f, 0.0f); int type = -1; while (getline(ss, tmp, ',')) { switch (cnt % MAX_DATAPARAM) { case DP_BID: break; case DP_EID: eid = stoi(tmp); if (eid <= 0) { pFBlock = CFieldBlock::Create(); pFBlock->Init(); } break; case DP_TEX: { #ifdef _MULTI_THREAD_NOWLOADING EnterCriticalSection(CGame::GetCriticalSection()); #endif LPTSTR ws = new TCHAR[tmp.size() + 1]; mbstowcs(ws, tmp.c_str(), tmp.size()); ws[tmp.size()] = '\0'; pObj = CCharacter::Create(ws); pObj->Init(); delete[] ws; #ifdef _MULTI_THREAD_NOWLOADING LeaveCriticalSection(CGame::GetCriticalSection()); #endif break; } case DP_POSX: pObj->TranslateX(stof(tmp)); break; case DP_POSY: pObj->TranslateY(stof(tmp)); break; case DP_POSZ: pObj->TranslateZ(stof(tmp)); break; case DP_WIDTH: width = stof(tmp); break; case DP_HEIGHT: height = stof(tmp); pObj->Resize(D3DXVECTOR2(width, height)); break; case DP_ANGLE: pObj->RotateZ(stof(tmp)); break; case DP_COLR: color.x = stof(tmp); break; case DP_COLG: color.y = stof(tmp); break; case DP_COLB: color.z = stof(tmp); pObj->SetColor(color); break; case DP_COLA: pObj->SetAlpha(stoi(tmp)); break; case DP_COLFLG: if (eid <= 0) { m_pFieldBlock.push_back(pFBlock); } if(stoi(tmp) > 0) m_pFieldBlock.back()->SetElement(pObj); break; case DP_TYPE: { // 0:普通のフィールドブロック // 1:クリア条件フィールドブロック // 2:障害フィールドブロック // 3:レイアウトブロック // 4:レイアウトオブジェクト type = stoi(tmp); switch(type) { case BT_NORMAL: case BT_CLEAR: case BT_OVER: m_pFieldBlock.back()->SetType(type); break; case BT_LAYOUT: m_pLayoutBlock.push_back(pObj); break; case BT_LAYOUTOBJ: m_pLayoutObject.push_back(pObj); break; } break; } case DP_TEX_NO: if(type == BT_LAYOUTOBJ) m_pLayoutObject.back()->UVDivision(stoi(tmp), LAYOUTOBJ_HFRAME, LAYOUTOBJ_VFRAME); break; default: break; } ++cnt; // 次のデータへ if (cnt >= MAX_DATAPARAM) { getline(ss, tmp); // 改行をスキップ cnt = 0; } } return true; }