static bool _BuildExecutablePath( const VFilePath &inPath, VFilePath& outExecutablePath) { bool ok; if (inPath.IsFile()) { outExecutablePath = inPath; ok = true; } else if (inPath.IsFolder()) { // if path is a folder named truc.someextension, // look at truc.someextension\Contents\Windows\truc.dll // afabre : finally, we look the dll near the exe file VString name; inPath.GetName( name); outExecutablePath = inPath; outExecutablePath = outExecutablePath.ToParent().ToParent(); outExecutablePath.SetFileName( name); outExecutablePath.SetExtension( CVSTR( "dll")); ok = true; } else { ok = false; } return ok; }
void VMacResFile::DebugTest() { // look for a "test.rsrc" file in same folder as the app // and duplicate it VFilePath sourcePath = VProcess::Get()->GetExecutableFolderPath(); sourcePath.SetFileName(VStr63("test.rsrc")); DebugMsg("Looking for file = %V\n", &sourcePath); VMacResFile srcFile(sourcePath, FA_READ, false); sourcePath.SetFileName(VStr63("test copy.rsrc")); VMacResFile dstFile(sourcePath, FA_READ_WRITE, true); VError error = srcFile.CopyResourcesInto(dstFile); dstFile.Close(); srcFile.Close(); }
VJSRequestHandler* VRPCService::_CreateRequestHandlerForMethods() { // TBD: use a module function handler instead of a global function handler VRIAJSCallbackGlobalFunction *callback = new VRIAJSCallbackGlobalFunction( L"doRequest"); VJSRequestHandler *handler = new VJSRequestHandler( fApplication, fPatternForMethods, callback); if (handler != NULL) { handler->SetEnable( true); VFilePath rpcImpl; VRIAServerApplication::Get()->GetWAFrameworkFolderPath( rpcImpl); rpcImpl.ToSubFolder( L"Core").ToSubFolder( L"Runtime").ToSubFolder( L"rpcService"); rpcImpl.SetFileName( L"rpc-server.js", true); VFile *file = new VFile( rpcImpl); handler->RegisterIncludedFile( file); QuickReleaseRefCountable( file); } return handler; }
VFolder *XWinFolderIterator::_GetPath( const VString& inFileName, DWORD inAttributes) { VFolder *path = NULL; if (inFileName[0] != CHAR_FULL_STOP) { bool isInvisible = (inAttributes & FILE_ATTRIBUTE_HIDDEN) ? true : false; bool isFolder = (inAttributes & FILE_ATTRIBUTE_DIRECTORY) ? true : false; if (!isInvisible || (fOptions & FI_WANT_INVISIBLES)) { if (isFolder) { if (fOptions & FI_WANT_FOLDERS) { VFilePath currentPath; currentPath.FromFilePath( fRootPath); currentPath.ToSubFolder( inFileName); path = new VFolder(currentPath); } } else { // it's a file, maybe it's an alias to a folder if (fOptions & FI_RESOLVE_ALIASES) { VFilePath currentPath; currentPath.FromFilePath( fRootPath); currentPath.SetFileName( inFileName); VFile theFile( currentPath); if (theFile.IsAliasFile()) { VFilePath resolvedPath; if ( (theFile.ResolveAlias( resolvedPath) == VE_OK) && resolvedPath.IsFolder()) path = new VFolder( resolvedPath); } } } } } return path; }
XBOX::VError VRPCService::GetProxy( XBOX::VString& outProxy, const XBOX::VString& inModulePath, const XBOX::VString& inNamespace, const IHTTPRequest* inRequest, IHTTPResponse* inResponse) { VError err = VE_OK; outProxy.Clear(); if (fApplication != NULL) { VRIAContext *riaContext = fApplication->RetainNewContext( err); if (err == VE_OK) { VRPCCatalog *catalog = fApplication->RetainRPCCatalog( riaContext, &err, inRequest, inResponse); if (err == VE_OK) { if (catalog != NULL) { MapOfRPCSchema schemas; err = catalog->RetainSchemasByModule( inModulePath, schemas); if (err == VE_OK) { // Build the proxy VFile *bodyFile = NULL, *templateFile = NULL; VFilePath path; VRIAServerApplication::Get()->GetWAFrameworkFolderPath( path); path.ToSubFolder( L"Core").ToSubFolder( L"Runtime").ToSubFolder( L"rpcService"); path.SetFileName( L"proxy-body.js", true); bodyFile = new VFile( path); if (bodyFile == NULL) err = vThrowError( VE_MEMORY_FULL); if (err == VE_OK) { path.SetFileName( L"proxy-template.js", true); templateFile = new VFile( path); if (templateFile == NULL) err = vThrowError( VE_MEMORY_FULL); } if (err == VE_OK && bodyFile->Exists() && templateFile->Exists()) { VString templateString; VFileStream bodyStream( bodyFile); VFileStream templateStream( templateFile); err = bodyStream.OpenReading(); if (err == VE_OK) templateStream.OpenReading(); if (err == VE_OK) err = bodyStream.GetText( outProxy); if (err == VE_OK) { VValueBag bag; bag.SetString( L"rpc-pattern", fPatternForMethods); bag.SetString( L"publishInGlobalNamespace", (fPublishInClientGlobalNamespace) ? L"true" : L"false"); outProxy.Format( &bag); } if (err == VE_OK) err = templateStream.GetText( templateString); if (err == VE_OK) { if (templateString.BeginsWith( L"/*")) { // sc 28/08/2014, remove the copyright VIndex end = templateString.Find( L"*/"); if (end > 0) { templateString.Remove( 1, end + 1); } } for (MapOfRPCSchema::const_iterator iter = schemas.begin() ; iter != schemas.end() ; ++iter) { VValueBag bag; bag.SetString( L"function-name", iter->first.GetMethodName()); bag.SetString( L"namespace", inNamespace); bag.SetString( L"modulePath", inModulePath); VString proxy( templateString); proxy.Format( &bag); outProxy.AppendString( proxy); } } bodyStream.CloseReading(); templateStream.CloseReading(); } else { err = vThrowError( VE_FILE_NOT_FOUND); } QuickReleaseRefCountable( bodyFile); QuickReleaseRefCountable( templateFile); } } else { err = vThrowError( VE_RIA_RPC_CATALOG_NOT_FOUND); } } } ReleaseRefCountable( &riaContext); } return err; }
VError VRIAServerSolution::_Open( VSolution* inDesignSolution, VRIAServerSolutionOpeningParameters *inOpeningParameters) { if (fState.opened) return VE_OK; VError err = VE_OK; if (!testAssert(fDesignSolution == NULL)) err = VE_UNKNOWN_ERROR; if (err == VE_OK && inDesignSolution == NULL) err = ThrowError( VE_RIA_INVALID_DESIGN_SOLUTION); if (err == VE_OK) { fDesignSolution = inDesignSolution; fDesignSolution->GetName( fName); CopyRefCountable( &fOpeningParameters, inOpeningParameters); if (fOpeningParameters == NULL) { fOpeningParameters = new VRIAServerSolutionOpeningParameters(); if (fOpeningParameters == NULL) err = ThrowError( VE_MEMORY_FULL); } if (err == VE_OK) fState.inMaintenance = fOpeningParameters->GetOpeningMode() == eSOM_FOR_MAINTENANCE; if (err == VE_OK && !fState.inMaintenance) { VSize nNameLength = fName. GetLength ( ) * 2 + 1; char* szchName = new char [ nNameLength ]; fName. ToCString ( szchName, nNameLength ); fprintf ( stdout, "Publishing solution \"%s\"\n", szchName ); delete [ ] szchName; } if (err == VE_OK && !fState.inMaintenance) { const VFolder * vfRoot = RetainFolder ( ); if ( vfRoot != 0 ) { VJSGlobalContext::SetSourcesRoot ( *vfRoot ); vfRoot-> Release ( ); VJSGlobalContext::AllowDebuggerLaunch ( ); } } fLoggerID = L"com.wakanda-software." + fName; if (err == VE_OK && !fState.inMaintenance) { // Create a messages logger VFolder *logFolder = RetainLogFolder( true); if (logFolder != NULL) { fLogger = new VLog4jMsgFileLogger( *logFolder, fName + L"_log"); if (fLogger == NULL) { err = ThrowError( VE_MEMORY_FULL); } else { VRIAServerApplication::Get()->SetLogger( fLogger); fLogger->Start(); } logFolder->Release(); } else { err = ThrowError( VE_RIA_LOG_FOLDER_NOT_FOUND); } } StUseLogger logger; if (err == VE_OK && !fState.inMaintenance) { // Create a log file reader fLogReader = new VLog4jMsgFileReader(); if (fLogReader == NULL) err = ThrowError( VE_MEMORY_FULL); else fLogger->AttachReader( fLogReader); } if (err == VE_OK || fState.inMaintenance) { StErrorContextInstaller errContext; VMicrosecondsCounter usCounter; usCounter.Start(); logger.Log( fLoggerID, eL4JML_Information, L"Opening the solution"); if (err == VE_OK && !fState.inMaintenance) { fJSRuntimeDelegate = new VRIAServerSolutionJSRuntimeDelegate( this); if (fJSRuntimeDelegate == NULL) err = ThrowError( VE_MEMORY_FULL); } if (err == VE_OK && !fState.inMaintenance) { fJSContextPool = VRIAServerApplication::Get()->GetJSContextMgr()->CreateJSContextPool( err, this); } if (err == VE_OK || fState.inMaintenance) { // Load all available settings files err = _LoadFileSettings(); if (err != VE_OK) err = ThrowError( VE_RIA_CANNOT_LOAD_SETTINGS_FILES); } if (err == VE_OK || fState.inMaintenance) { // Load the database settings err = _LoadDatabaseSettings(); if (err != VE_OK) err = ThrowError( VE_RIA_CANNOT_LOAD_DATABASE_SETTINGS); } if (err == VE_OK || fState.inMaintenance) { // Load users and groups directory fUAGDirectory = _OpenUAGDirectory( err); if (err != VE_OK) err = ThrowError( VE_RIA_CANNOT_LOAD_UAG_DIRECTORY); } if (err == VE_OK || fState.inMaintenance) { // Build the ServerAdmin project file path VFilePath serverAdminProjectPath; VFolder *folder = VRIAServerApplication::Get()->RetainApplicationResourcesFolder(); if (folder != NULL) { folder->GetPath( serverAdminProjectPath); serverAdminProjectPath.ToSubFolder( L"Default Solution"); serverAdminProjectPath.ToSubFolder( L"Admin"); // sc 18/02/2011 "ServerAdmin" become "Admin" serverAdminProjectPath.SetFileName( L"ServerAdmin", false); serverAdminProjectPath.SetExtension( RIAFileKind::kProjectFileExtension); } ReleaseRefCountable( &folder); // Opening the applications if (fApplicationsMutex.Lock()) { // Note: the ServerAdmin project may be the project of the default solution // or the ServerAdmin project added to a solution which has none admin project. bool hasAdmin = false; VProject *serverAdminProject = fDesignSolution->GetProjectFromFilePathOfProjectFile( serverAdminProjectPath); bool ignoreProjectOpeningErrors = !fSettings.GetStopIfProjectFails(); fGarbageCollect = fSettings.GetGarbageCollect(); VectorOfProjects designProjects; fDesignSolution->GetVectorOfProjects( designProjects); for (VectorOfProjects::iterator iter = designProjects.begin() ; iter != designProjects.end() && (err == VE_OK || fState.inMaintenance) ; ++iter) { if (*iter != NULL) { VRIAServerProject *application = NULL; // Create opening parameters VRIAServerProjectOpeningParameters *projectOpeningParams = new VRIAServerProjectOpeningParameters(); if (projectOpeningParams != NULL) { projectOpeningParams->SetOpeningMode( fState.inMaintenance ? ePOM_FOR_MAINTENANCE : ePOM_FOR_RUNNING); sLONG defaultAdminPort = 0; if (*iter == serverAdminProject && fOpeningParameters->GetCustomAdministratorHttpPort( defaultAdminPort)) projectOpeningParams->SetCustomHttpPort( defaultAdminPort); // for Default solution, pass the WebAdmin opening parameters application = VRIAServerProject::OpenProject( err, this, *iter, projectOpeningParams); if ((application != NULL) && (err == VE_OK || fState.inMaintenance)) { VUUID uuid; xbox_assert(application->GetUUID( uuid)); fApplicationsCollection.push_back( VRefPtr<VRIAServerProject>(application)); fApplicationsMap[uuid] = VRefPtr<VRIAServerProject>(application); hasAdmin |= application->IsAdministrator(); if (!fState.inMaintenance) { VString vstrHostName; VString vstrIP; sLONG nPort = 0; VString vstrPattern; VString vstrPublishName; VError vErrorS = application-> GetPublicationSettings ( vstrHostName, vstrIP, nPort, vstrPattern, vstrPublishName ); xbox_assert ( vErrorS == VE_OK ); vstrPublishName. Clear ( ); application-> GetName ( vstrPublishName ); VString vstrMessage; vstrMessage. AppendCString ( "\tProject \"" ); vstrMessage. AppendString ( vstrPublishName ); vstrMessage. AppendCString ( "\" published at " ); vstrMessage. AppendString ( vstrIP ); vstrMessage. AppendCString ( " on port " ); vstrMessage. AppendLong ( nPort ); vstrMessage. AppendCString ( "\n" ); VSize nNameLength = vstrMessage. GetLength ( ) * 2 + 1; char* szchName = new char [ nNameLength ]; vstrMessage. ToCString ( szchName, nNameLength ); fprintf ( stdout, szchName ); delete [ ] szchName; } } ReleaseRefCountable( &projectOpeningParams); } else { err = ThrowError( VE_MEMORY_FULL); } if (err != VE_OK) { VString name; (*iter)->GetName( name); VErrorBase *errBase = CreateErrorBase( VE_RIA_CANNOT_OPEN_PROJECT, &name, NULL); logger.LogMessageFromErrorBase( fLoggerID, errBase); ReleaseRefCountable( &errBase); if (!fState.inMaintenance) { if (application != NULL) application->Close(); if (ignoreProjectOpeningErrors) err = VE_OK; else err = VE_RIA_CANNOT_OPEN_PROJECT; } } ReleaseRefCountable( &application); } } if (!hasAdmin && !fState.inMaintenance && (err == VE_OK)) { VFile file( serverAdminProjectPath); if (file.Exists()) { VURL url( serverAdminProjectPath); fDesignSolution->AddExistingProject( url, false); VProject *designProject = fDesignSolution->GetProjectFromFilePathOfProjectFile( serverAdminProjectPath); if (designProject != NULL) { VRIAServerProject *application = NULL; // Create opening parameters VRIAServerProjectOpeningParameters *projectOpeningParams = new VRIAServerProjectOpeningParameters(); if (projectOpeningParams != NULL) { projectOpeningParams->SetOpeningMode( ePOM_FOR_RUNNING); sLONG defaultAdminPort = 0; if (fOpeningParameters->GetCustomAdministratorHttpPort( defaultAdminPort)) projectOpeningParams->SetCustomHttpPort( defaultAdminPort); application = VRIAServerProject::OpenProject( err, this, designProject, projectOpeningParams); if (application != NULL && err == VE_OK) { VUUID uuid; xbox_assert(application->GetUUID( uuid)); fApplicationsCollection.push_back( VRefPtr<VRIAServerProject>(application)); fApplicationsMap[uuid] = VRefPtr<VRIAServerProject>(application); } ReleaseRefCountable( &projectOpeningParams); } else { err = ThrowError( VE_MEMORY_FULL); } if (err != VE_OK) { VString name; designProject->GetName( name); VErrorBase *errBase = CreateErrorBase( VE_RIA_CANNOT_OPEN_PROJECT, &name, NULL); logger.LogMessageFromErrorBase( fLoggerID, errBase); ReleaseRefCountable( &errBase); if (application != NULL) application->Close(); if (ignoreProjectOpeningErrors) err = VE_OK; else err = VE_RIA_CANNOT_OPEN_PROJECT; } ReleaseRefCountable( &application); } } } fApplicationsMutex.Unlock(); } } logger.LogMessagesFromErrorContext( fLoggerID, errContext.GetContext()); if (err == VE_OK) { VString logMsg; logMsg.Printf( "Solution opened (duration: %i ms)", usCounter.Stop()/1000); logger.Log( fLoggerID, eL4JML_Information, logMsg); } } } fState.opened = true; return err; }