XString getFilenameExtension(XString s) { int i = s.findRev('.'); s = s.mid(i + 1); return s; }
int GameLoop::InitInstance() { int code = App::InitInstance(); InitCommonControls(); //img_pacman = ImageList_LoadBitmap(App::GetInstance(), MAKEINTRESOURCE(IDB_BITMAP1),32, 0, RGB(255, 0, 255)); XString title; title.LoadFromResource(IDS_APP_TITLE); XString wclass; wclass.LoadFromResource(IDC_OOPACMAN); RECT rect = game->get_map()->get_rect(); DWORD style = WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME; AdjustWindowRect(&rect, style, FALSE); if (!window.CreateWnd(title, style, CW_USEDEFAULT, 0, rect.right-rect.left, rect.bottom-rect.top, NULL, LPCTSTR(NULL)) ) return 1; SetMainWindow(&window); window.ShowWindow(_cmdShow); window.UpdateWindow(); return code; }
CKERROR LoadCallBack(CKUICallbackStruct& loaddata,void*) { if (GetPlayer().GetPAppStyle()->UseSplash() && GetPlayer().GetPAppStyle()->ShowLoadingProcess()) { if(loaddata.Reason == CKUIM_LOADSAVEPROGRESS ){ if (loaddata.NbObjetsLoaded % 10 == 0) { float progress = (static_cast<float>(loaddata.NbObjetsLoaded) / static_cast<float>(loaddata.NbObjetsToLoad)) ; progress *=100; int out = static_cast<int>(progress); XString percStr; percStr.Format("Load... %d %s",out,"%"); if (xSplash::GetSplash()) { GetPlayer().SetSplashText(percStr.Str()); if (progress > 99.9F) { GetPlayer().HideSplash(); //Sleep(3000); } } } } } return CK_OK; }
/* ******************************************************************* * Function: IGBLSMConfigurationAccess::RemoveCIS * * Description: Removes a CIS and all associated CIs from persistent storage. * * * Parameters: * CGBLCISID cisid * * Returns: * CGBLCOError * ******************************************************************* */ CGBLCOError IGBLSMConfigurationAccess::RemoveCIS( CGBLCISID cisid ) { CGBLCOError error(CGBLCOError::EGBLCOErrorType::GBLCO_OK); // Check we're actually connected to the server first... if ( !(storageManager->IsConnected()) ) { error = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLSM_ERROR_PROFILEACCESS_NO_CONNECTION_DESC, GBLSM_ERROR_PROFILEACCESS_NO_CONNECTION ); } else { XString query; XString dbName; storageManager->GetDbName( dbName ); query << "DELETE FROM " << dbName << ".ciss WHERE ID=" << (int)cisid; // Now execute it and check the response... int queryResult = storageManager->ExecuteBlockingSQL( query.Str() ); if( queryResult != CGBLSMStorageManager::EGBLStorageManagerExecutionStatus::NoResult ) { error = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLSM_ERROR_GENERAL_SQL_ERROR_DESC, GBLSM_ERROR_GENERAL_SQL_ERROR); } } return error; }
//************************************ // Method: GetDocument // FullName: vtPhysics::pFactory::GetDocument // Access: public // Returns: TiXmlDocument* // Qualifier: // Parameter: XString filename //************************************ TiXmlDocument* pFactory::getDocument(XString filename) { XString fname(filename.Str()); if ( fname.Length() ) { XString fnameTest = ResolveFileName(fname.CStr()); if ( fnameTest.Length()) { TiXmlDocument* result = new TiXmlDocument(fnameTest.Str()); result->LoadFile(fnameTest.Str()); result->Parse(fnameTest.Str()); TiXmlNode* node = result->FirstChild( "vtPhysics" ); if (!node) { GetPMan()->m_Context->OutputToConsoleEx("PFactory : Couldn't load Document : %s",filename.Str()); return NULL; }else { return result; } } } return NULL; }
/* ******************************************************************* * Function: IGBLSMLAEAccess::RemoveUser * * Description: Removes the association between a user and an LAE. * * * Parameters: * CGBLLAEID laeid * CGBLUserID user * * Returns: * CGBLCOError * ******************************************************************* */ CGBLCOError IGBLSMLAEAccess::RemoveUser( CGBLLAEID laeid, CGBLUserID user ) { CGBLCOError error(CGBLCOError::EGBLCOErrorType::GBLCO_OK); // Check we're actually connected to the server first... if ( !(storageManager->IsConnected()) ) { error = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLSM_ERROR_PROFILEACCESS_NO_CONNECTION_DESC, GBLSM_ERROR_PROFILEACCESS_NO_CONNECTION ); } else { XString query; XString dbName; // Get the name of the DB we're using storageManager->GetDbName(dbName); // Now build the query query = ""; query << "DELETE FROM " << dbName << ".EventUsers WHERE LAEID=" << (int)laeid << " AND UserID=" << (int)user; // Execute the query int deleteResult = storageManager->ExecuteBlockingSQL( query.Str() ); if( deleteResult != CGBLSMStorageManager::EGBLStorageManagerExecutionStatus::NoResult ) { error = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLSM_ERROR_GENERAL_SQL_ERROR_DESC, GBLSM_ERROR_GENERAL_SQL_ERROR); } } return error; }
void Add2() { XString str = L"Hello"; str += L" "; str += L"World"; wprintf(L"%s\n", str.GetString()); }
CGBLCOError GBLCommon::ResourceTools::SaveObject( CKBeObject*beo, XString filename) { if (!beo) { return CGBLCOError(CGBLCOError::GBLCO_LOCAL,"Invalid Object",GBL_ERROR_ID_GBL_COMMON); } //todo : adding checks for saving ability if(!filename.Length()) { return CGBLCOError(CGBLCOError::GBLCO_LOCAL,"No path specified",GBL_ERROR_ID_GBL_COMMON); } CKERROR res = CK_OK; CKObjectArray* oa = CreateCKObjectArray(); oa->InsertAt(beo->GetID()); res = beo->GetCKContext()->Save(filename.Str(),oa,0xFFFFFFFF,NULL); DeleteCKObjectArray(oa); return CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL,CKErrorToString(res),GBL_ERROR_ID_GBL_COMMON); }
void pWheel2::setWheelContactScript(int val) { CKBehavior * beh = (CKBehavior*)GetPMan()->GetContext()->GetObject(val); if (!beh) return; XString errMessage; if (!GetPMan()->checkCallbackSignature(beh,CB_OnWheelContactModify,errMessage)) { xError(errMessage.Str()); return; } pCallbackObject::setWheelContactScript(val); wheelContactModifyCallback = new pWheelContactModify(); wheelContactModifyCallback->setWheel(this); getWheelShape()->setUserWheelContactModify((NxUserWheelContactModify*)wheelContactModifyCallback); //---------------------------------------------------------------- //track information about callback getBody()->getCallMask().set(CB_OnWheelContactModify,true); }
int GetLastFileName(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; XString Inpath (ctx->GetLastCmoLoaded()); CKParameterOut *pout = beh->GetOutputParameter(0); pout->SetStringValue(Inpath.Str()); PathRemoveFileSpec(Inpath.Str()); CKParameterOut *pout2 = beh->GetOutputParameter(1); pout2->SetStringValue(Inpath.Str()); beh->ActivateOutput(0); return 0; }
BOOL MyAppWindow :: SaveFile( void ) { XFile savefile; XString s; mle->GetText( &s ); /* now open the file, create a new one if the given filename is not existing, otherwise overwrite */ /* it. open the file for write-access, dont allow any other programm to use the file while it is open*/ if( savefile.Open( path, XFILE_CREATE_IF_NEW | XFILE_REPLACE_EXISTING, XFILE_SHARE_DENYNONE | XFILE_WRITEONLY, s.GetLength()) == 0) { /* set the file-cursor to the beginning of the file */ savefile.Seek( 0, FILE_BEGIN); /*save the string */ savefile.Write ( (char*) s, s.GetLength()); /* close the file */ savefile.Close(); saved = TRUE; return TRUE; } else { XMessageBox( "could not open file", "error", MB_OK| MB_ERROR); return FALSE; } }
void CGBLStorageManagerTestBBBase::StopAndShowTimeMeasure(ofstream &_trace, float &totalTime) { float executionTime = TimeDiff(); totalTime += executionTime; XString disp = ""; disp << executionTime; _trace << "Execution time: " << disp.Str() << " seconds" <<endl; }
inline void WBUF_STRING(uint8_t *p, size_t pos, XString s, size_t len) { char *const begin = static_cast<char *>(WBUFP(p, pos)); char *const end = begin + len; char *const mid = std::copy(s.begin(), s.end(), begin); std::fill(mid, end, '\0'); }
inline void WFIFO_STRING(int fd, size_t pos, XString s, size_t len) { char *const begin = static_cast<char *>(WFIFOP(fd, pos)); char *const end = begin + len; char *const mid = std::copy(s.begin(), s.end(), begin); std::fill(mid, end, '\0'); }
bool read_constdb(ZString filename) { io::ReadFile in(filename); if (!in.is_open()) { PRINTF("can't read %s\n"_fmt, filename); return false; } bool rv = true; AString line_; while (in.getline(line_)) { // is_comment only works for whole-line comments // that could change once the Z dependency is dropped ... LString comment = "//"_s; XString line = line_.xislice_h(std::search(line_.begin(), line_.end(), comment.begin(), comment.end())).rstrip(); if (!line) continue; // "%m[A-Za-z0-9_] %i %i" // TODO promote either qsplit() or asplit() auto _it = std::find(line.begin(), line.end(), ' '); auto name = line.xislice_h(_it); auto _rest = line.xislice_t(_it); while (_rest.startswith(' ')) _rest = _rest.xslice_t(1); auto _it2 = std::find(_rest.begin(), _rest.end(), ' '); auto val_ = _rest.xislice_h(_it2); auto type_ = _rest.xislice_t(_it2); while (type_.startswith(' ')) type_ = type_.xslice_t(1); // yes, the above actually DTRT even for underlength input int val; int type = 0; // Note for future archeaologists: this code is indented correctly if (std::find_if_not(name.begin(), name.end(), [](char c) { return ('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || (c == '_'); }) != name.end() || !extract(val_, &val) || (!extract(type_, &type) && type_)) { PRINTF("Bad const line: %s\n"_fmt, line_); rv = false; continue; } P<str_data_t> n = add_strp(name); n->type = type ? StringCode::PARAM : StringCode::INT; n->val = val; } return rv; }
LRESULT WINAPI CustomItemOptionsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: { SHINITDLGINFO shidi; shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN; shidi.hDlg = hDlg; SHInitDialog(&shidi); LoadSettings(); SendMessage(GetDlgItem(hDlg, IDC_LEFT_FORMAT), WM_SETTEXT, NULL, (LPARAM) g_xsLeftFormat.GetBuffer()); SendMessage(GetDlgItem(hDlg, IDC_RIGHT_FORMAT), WM_SETTEXT, NULL, (LPARAM) g_xsRightFormat.GetBuffer()); HWND hWndTextSize = GetDlgItem(hDlg, IDC_TEXT_SIZE); InitializeComboBox(hWndTextSize); SendMessage(hWndTextSize, CB_ADDSTRING, NULL, (LPARAM) _T("System Default")); for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++) { TCHAR szNumber[1]; _itot(i, szNumber, 10); SendMessage(hWndTextSize, CB_ADDSTRING, NULL, (LPARAM) szNumber); //SendMessage(hWndTextSize, CB_ADDSTRING, NULL, (LPARAM) szNumber); } SendMessage(hWndTextSize, CB_SETCURSEL, (WPARAM) g_iTextSize, NULL); } return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK) { TCHAR szBuffer[MAX_LOADSTRING]; SendMessage(GetDlgItem(hDlg, IDC_LEFT_FORMAT), WM_GETTEXT, (WPARAM) MAX_LOADSTRING, (LPARAM) szBuffer); g_xsLeftFormat = szBuffer; SendMessage(GetDlgItem(hDlg, IDC_RIGHT_FORMAT), WM_GETTEXT, (WPARAM) MAX_LOADSTRING, (LPARAM) szBuffer); g_xsRightFormat = szBuffer; g_iTextSize = SendMessage(GetDlgItem(hDlg, IDC_TEXT_SIZE), CB_GETCURSEL, NULL, NULL); SaveSettings(); EndDialog(hDlg, LOWORD(wParam)); return TRUE; } return FALSE; } return FALSE; }
/* load a file */ BOOL MyAppWindow :: LoadFile ( char * p) { // is there already a file loaded or has the user entered some text? if(loaded == FALSE && saved == TRUE) { //no, we load the file in the window of the current thread XFile loadfile; /* now open the file, fail if given filename is not existing */ /* open the file for read-access, dont allow any other programm to use the file while it is open*/ if( loadfile.Open( p, XFILE_FAIL_IF_NEW | XFILE_OPEN_EXISTING, XFILE_SHARE_DENYWRITE | XFILE_READONLY ) == 0) { XString s; loading = TRUE; //how large is the file? XFileInfo info; loadfile.GetFileInfo( &info ); LONG size = info.GetFileSize(); //read the complete file loadfile.Read ( (PVOID) s.GetBuffer(info.GetFileSize() + 1), size); s.ReleaseBuffer( info.GetFileSize() ); //set the XString content to the mle mle->SetText( s ); //dontïforget to close the file loadfile.Close(); loaded = TRUE; path = p; mle->SetFocus(); GetText( &s ); s+= " - "; s+= p; SetText( s ); loading = FALSE; return TRUE; } else { XMessageBox( p, "couldnït open File!", MB_OK|MB_ERROR); return FALSE; } } else { //there is a file loaded, or the user has entered some text, so // we create a new window and load the file // XResource res( IDM_MAIN, ((MyApp*) GetProcess())->GetResourceLibrary()); MyAppWindow * win = new MyAppWindow( IDM_MAIN ); win->LoadFile(p); return TRUE; } }
XString getFilenameWithoutPathAndExtension(XString s) { XString k = getFilenameWithoutPath(s); int i = k.findRev('.'); k = k.left(i); return k; }
XString getFilenameWithoutPath(XString s) { int i = s.findRev('\\'); if (i == -1){ i = s.findRev('/'); } s = s.right(s.length() - i - 1); return s; }
bool IsEqual(const XString& str1,const XString& str2) { if(str1.length() != str2.length()) return false; XString v1(str1); XString v2(str2); ToLower(v1); ToLower(v2); return v1 == v2; }
bool EndsWith(const XString& str,const XString& substr) { if(substr.length() > str.length()) return false; for (XString::size_type i=str.length()-1,j=substr.length()-1;j>0;--i,--j) { if(substr[j] != str[i]) return false; } return true; }
bool StartsWith(const XString& str,const XString& substr) { if(substr.length() > str.length()) return false; for (XString::size_type i=0;i<substr.length();++i) { if(substr[i] != str[i]) return false; } return true; }
void PhysicManager::_checkObjectsByAttribute(CKScene *newScene) { CKAttributeManager* attman = m_Context->GetAttributeManager(); int sizeJFuncMap = ATT_FUNC_TABLE_SIZE;//(sizeof(*getRegistrationTable()) / sizeof((getRegistrationTable())[0])); for (int fIndex = 0 ; fIndex < sizeJFuncMap ; fIndex ++) { std::vector<int>attributeIdList; pFactory::Instance()->findAttributeIdentifiersByGuid(getRegistrationTable()[fIndex].guid,attributeIdList); int attCount = attributeIdList.size(); for (int i = 0 ; i < attCount ; i++ ) { int currentAttType = attributeIdList.at(i); const XObjectPointerArray& Array = attman->GetAttributeListPtr( attributeIdList.at(i) ); for (CKObject** it = Array.Begin(); it != Array.End(); ++it) { CK3dEntity *target = static_cast<CK3dEntity*>(*it); if (target) { XString error; error.Format("Registering :%s with %s",target->GetName(),attman->GetAttributeNameByType(currentAttType)); //if(!strcmp( target->GetName(),"smutan3-3" ) ) { // xLogger::xLog(XL_START,ELOGTRACE,E_LI_MANAGER,"problem case" ); } // CKScene *levelScene = GetContext()->GetCurrentLevel()->GetCurrentScene(); // we check as no scene is current in use if ( ( GetContext()->GetCurrentLevel()->GetLevelScene() == newScene && !isSceneObject2(target) ) || ( newScene && newScene->IsObjectHere(target) && newScene !=GetContext()->GetCurrentLevel()->GetLevelScene() ) || ( newScene && GetContext()->GetCurrentLevel()->GetCurrentScene() && GetContext()->GetCurrentLevel()->GetCurrentScene() == newScene && newScene !=GetContext()->GetCurrentLevel()->GetLevelScene() && newScene->IsObjectHere(target) ) || ( (physicFlags & PMF_DONT_DELETE_SCENES) ) ) { xLogger::xLog(XL_START,ELOGTRACE,E_LI_MANAGER,error.CStr() ); (*getRegistrationTable()[fIndex].rFunc)(target,currentAttType,true,false); GetPMan()->getCheckList().PushBack(target->GetID()); } } } } } }
void ClientSideResponse::DebugPrintRequest() { XString method = GetHeader(XString("method")); XString response_code = GetHeader(XString("response_code")); XString http_version = GetHeader(XString("http_version")); printf("method = %s\n", method.c_str()); printf("response_code = %s\n", response_code.c_str()); printf("http_version = %s\n", http_version.c_str()); fflush(stdout); }
void CGBLStorageManagerTestBBBase::OutputTestText( CKContext *ctx, XString &text ) { // Write to output if we can... if( ctx ) { ctx->SendInterfaceMessage(CKUIM_SENDNOTIFICATION, (CKDWORD)text.Str(),0,CUIK_NOTIFICATION_DEBUGMESSAGE); ctx->OutputToConsole(text.Str(),false); } }
void GetBuffer() { XString str = L"Hello"; wchar_t* p = str.GetBuffer(20); wcscpy_s(p, 20, L"Hello World"); str.ReleseBuffer(); str += L"!"; wprintf(L"%s\n", str.GetString()); }
/* ******************************************************************* * Function: CKERROR InitInstance( CKContext* theContext ) * * Description : If no manager is used in the plugin these functions * are optional and can be exported. Virtools will call * 'InitInstance' when loading the behavior library and * 'ExitInstance' when unloading it. It is a good place * to perform Attributes Types declaration, registering new * enums or new parameter types. * * Parameters : CKContext* theContext * * * Returns : CKERROR * ******************************************************************* */ CKERROR InitInstance( CKContext* theContext ) { new CGBLProfileManager( theContext ); CKParameterManager* pm = theContext->GetParameterManager(); //--- TODO: A Delete function needs to be registered, until then these will leak! CKParameterTypeDesc pProfile; pProfile.Guid = GUID_PROFILE_ID; pProfile.DerivedFrom = CKGUID(0,0); pProfile.TypeName = "TGBLProfileID"; pProfile.DefaultSize = sizeof(CGBLProfileID); pProfile.CreateDefaultFunction = CKProfileCreator; pProfile.StringFunction = CKProfileStringFunc; //pProfile.UICreatorFunction = pm->RegisterParameterType(&pProfile); CKParameterTypeDesc pTeam; pTeam.Guid = GUID_TEAM_ID; pTeam.DerivedFrom = GUID_PROFILE_ID; pTeam.TypeName = "TGBLTeamID"; pTeam.DefaultSize = sizeof(CGBLTeamID); pTeam.CreateDefaultFunction = CKTeamCreator; pTeam.StringFunction = CKProfileStringFunc; //pTeam.UICreatorFunction = pm->RegisterParameterType(&pTeam); CKParameterTypeDesc pUser; pUser.Guid = GUID_USER_ID; pUser.DerivedFrom = GUID_PROFILE_ID; pUser.TypeName = "TGBLUserID"; pUser.DefaultSize = sizeof(CGBLUserID); pUser.CreateDefaultFunction = CKUserCreator; pUser.StringFunction = CKProfileStringFunc; //pUser.UICreatorFunction = pm->RegisterParameterType(&pUser); // Prevent designer from creating a Profile ID as this is an invalid type. CKParameterTypeDesc* param_type; param_type = pm->GetParameterTypeDescription(GUID_PROFILE_ID); if (param_type) param_type->dwFlags|=CKPARAMETERTYPE_HIDDEN; CGBLTypeHandler THandler(theContext); XString typeList; THandler.GetTypesList(typeList); pm->RegisterNewEnum(EGBLProfileFieldTypeGUID, "EGBLProfileFieldType", typeList.Str()); pm->RegisterNewEnum(EGBLUserTypeGUID, "EGBLUserType", "Player=0,Facilitator=1"); return CK_OK; }
void renameFile(XString s, XString d) { XString k = ""; #ifdef WINDOWS // HIDE k = "move "; // HIDE k = k.append(s); // HIDE k = k.append(" "); // HIDE k = k.append(d); // HIDE system(k.ascii()); // HIDE #else // HIDE k = "mv "; // HIDE k = k.append(s); // HIDE k = k.append(" "); // HIDE k = k.append(d); // HIDE system(k.ascii()); // HIDE #endif // HIDE // UNHIDE k = "mv "; // UNHIDE k = k.append(s); // UNHIDE k = k.append(" "); // UNHIDE k = k.append(d); // UNHIDE system(k.ascii()); }
XString ReadStream::ReadString() { int len = ReadShort(); XString s; s.SetLen(len, 0); for(int i = 0; i < len; i++) { s.SetChar(i, (TCHAR)ReadShort()); } return s; }
void TrimLeft(XString& str) { for (XString::iterator i = str.begin();i !=str.end();++i) { if(!isspace(*i)) { str.erase(str.begin(),i); return; } } }