VFolder* VRIAServerSolution::RetainFolder() const
{
	VFolder *folder = NULL;

	if (fDesignSolution != NULL)
	{
		VProjectItem *item = fDesignSolution->GetSolutionFileProjectItem();
		if (item != NULL)
		{
			VFilePath path;
			item->GetFilePath( path);
			path = path.ToFolder();
			if (path.IsFolder())
			{
				folder = new VFolder( path);
				if (folder != NULL && !folder->Exists())
				{
					folder->Release();
					folder = NULL;
				}
			}
		}
	}	
	return folder;
}
VProjectItem* VProjectItemFile::Instantiate( const XBOX::VURL& inURL, VProjectItem *inParent, bool inExternalReference)
{
	VProjectItem *result = NULL;

	VFilePath path;
	if (inURL.GetFilePath( path))
	{
		if (path.IsFile())
		{
			VString fileName;
			path.GetFileName( fileName);

			VProjectItemFile *behaviour = new VProjectItemFile( NULL);
			if (behaviour != NULL)
			{
				result = new VProjectItem( behaviour);
				if (result != NULL)
				{
					result->SetURL( inURL);
					result->SetName( fileName);
					result->SetDisplayName( fileName);
					result->SetExternalReference( inExternalReference);

					if (inParent != NULL)
						inParent->AttachChild( result);
				}
			}
		}
	}
	return result;
}
VFile* XLinuxLibrary::RetainExecutableFile(const VFilePath &inFilePath) const
{
    //jmo - What are we supposed to retain ? First we try the exact path...

	if(inFilePath.IsFile())
		return new VFile(inFilePath);

    //jmo - If exact path doesn't work, we assume inFilePath to be part of a bundle
    //      and try to find the corresponding shared object.
    
    VFilePath bundlePath=inFilePath;

    while(!bundlePath.MatchExtension(CVSTR("bundle"), true /*case sensitive*/) && bundlePath.IsValid())
        bundlePath=bundlePath.ToParent();

    if(!bundlePath.IsValid())
        return NULL;

    VString name;
    bundlePath.GetFolderName(name, false /*no ext.*/);

    if(name.IsEmpty())
        return NULL;

    VString soSubPath=CVSTR("Contents/Linux/")+VString(name)+CVSTR(".so");

    VFilePath soPath;
    soPath.FromRelativePath(bundlePath, soSubPath, FPS_POSIX);
            
    if(soPath.IsFile())
        return new VFile(soPath);
    
    return NULL;
}
Exemplo n.º 4
0
/*
	static
*/
VError VFolder::ResolveAliasFolder( VFolder **ioFolder, bool inDeleteInvalidAlias)
{
	VError err = VE_OK;
	if ( (*ioFolder != NULL) && (*ioFolder)->fPath.IsFolder() && !(*ioFolder)->fFolder.Exists( false /* doesn't check alias */) )
	{
		// the folder doesn't exists
		// maybe is it an alias file?
		VString path = (*ioFolder)->fPath.GetPath();
		if (testAssert( path[path.GetLength()-1] == FOLDER_SEPARATOR))
		{
			path.Truncate( path.GetLength()-1);
			#if VERSIONWIN
			path += ".lnk";
			#endif
			VFile file( path);
			if (file.IsAliasFile() && file.Exists())
			{
				VFilePath resolvedPath;
				err = file.GetImpl()->ResolveAlias( resolvedPath);	// nothrow
				if (err == VE_OK)
				{
					if (resolvedPath.IsFolder())
					{
						(*ioFolder)->Release();
						*ioFolder = new VFolder( resolvedPath);
					}
					else if (inDeleteInvalidAlias)
					{
						err = file.Delete();
					}
					else
					{
						StThrowFileError errThrow( *ioFolder, VE_FILE_CANNOT_RESOLVE_ALIAS_TO_FOLDER);
						err = errThrow.GetError();
					}
				}
				else if (inDeleteInvalidAlias)
				{
					err = file.Delete();
				}
				else
				{
					if (IS_NATIVE_VERROR( err))
					{
						StThrowFileError errThrow( &file, VE_FILE_CANNOT_RESOLVE_ALIAS, err);
						err = errThrow.GetError();
					}
				}
			}
		}
	}
	return err;
}
VFolder* VProjectItemFolder::RetainFolder() const
{
	VFolder *folder = NULL;

	if (fOwner != NULL)
	{
		VFilePath path;
		if (fOwner->GetFilePath( path) && path.IsFolder())
			folder = new VFolder( path);
	}
	return folder;
}
VFile* VProjectItemFile::RetainFile() const
{
	VFile *file = NULL;

	if (fOwner != NULL)
	{
		VFilePath path;
		if (fOwner->GetFilePath( path) && path.IsFile())
			file = new VFile( path);
	}
	return file;
}
Exemplo n.º 7
0
VFilePath VProcess::GetExecutableFilePath() const
{
	VFilePath filePath;

#if VERSIONMAC

	CFURLRef exeURL = ::CFBundleCopyExecutableURL( ::CFBundleGetMainBundle());
	
	if (testAssert( exeURL != NULL ))
	{
		CFStringRef cfPath = ::CFURLCopyFileSystemPath( exeURL, kCFURLHFSPathStyle);
		if (testAssert( cfPath != NULL ))
		{
			VString thepath;
			thepath.MAC_FromCFString( cfPath);
			thepath.Compose();
			filePath.FromFullPath( thepath, FPS_SYSTEM);
			::CFRelease( cfPath);
		}
		
		::CFRelease(exeURL );
	}

#elif VERSIONWIN

	// Get a path to the exe.
	UniChar path[4096];
	DWORD pathLength=0;

	path[sizeof(path)/sizeof(UniChar)-2]=0;
	pathLength = ::GetModuleFileNameW(NULL, path, sizeof(path));
	
	if (testAssert(pathLength != 0 && !path[sizeof(path)/sizeof(UniChar)-2]))
	{
		VString thepath( path);
		filePath.FromFullPath( thepath, FPS_SYSTEM);
	}

#elif VERSION_LINUX

	PathBuffer path;

	VError verr=path.InitWithExe();
	xbox_assert(verr==VE_OK);

	path.ToPath(&filePath);
	xbox_assert(verr==VE_OK);
		
#endif
	
	return filePath;
}
Exemplo n.º 8
0
VError VArchiveStream::_AddFile(VFile& inFile,const VFilePath& inSourceFolder,const VString& inExtraInfo)
{
	XBOX::VError result = VE_FILE_NOT_FOUND;
	if ( inFile.Exists() )
	{
		///ACI0078887, O.R. Nov 29th 2012: mask error if file is already known, does no harm 
		result = VE_OK;
		if (!ContainsFile( &inFile))
		{
			VString relativePath;
			if(testAssert(!inSourceFolder.IsEmpty() && inFile.GetPath().GetRelativePath(inSourceFolder,relativePath)))
			{
				fUniqueFilesCollection->insert(inFile.GetPath());
				fFileExtra.push_back( inExtraInfo );
				fFileList.push_back( &inFile );
				fSourceFolderForFiles.push_back(inSourceFolder);	
			}
			else
			{
				///ACI0078887, O.R. Nov 29th 2012: explicitely fail if item is not relative to source folder, this should never happen
				result = VE_INVALID_PARAMETER;
			}
		}
	}
	return result;
}
Exemplo n.º 9
0
bool VLibrary::IsSameFile(const VFilePath &inLibFile) const
{
	VTaskLock	locker(&fCriticalSection);

	bool result = (fFilePath.GetPath().CompareToString(inLibFile.GetPath()) == CR_EQUAL);
	
	return result;
}
Exemplo n.º 10
0
Boolean XWinLibrary::Load( const VFilePath &inPath)
{
	VFilePath executablePath;
	if (_BuildExecutablePath( inPath, executablePath))
	{
		fInstance = ::LoadLibraryExW( executablePath.GetPath().GetCPointer(), NULL, 0);
	}
	
	if (fInstance == NULL)
	{
		XBOX::VString path( executablePath.GetPath());
		DebugMsg("VComponentManager erreur load %V\n", &path);
		StThrowFileError throwErr( inPath, VE_LIBRARY_CANNOT_LOAD, ::GetLastError());
		fInstance = NULL;
	}
	
	return fInstance != NULL;
}
Exemplo n.º 11
0
VFile* XLinuxFileIterator::XLinuxFileIterator::Next()
{
	PathBuffer path;
	PathBuffer* pathPtr=fIt->Next(&path, fOpts);

	if(pathPtr==NULL)
		return NULL;

	VFilePath tmpPath;
	pathPtr->ToPath(&tmpPath);

	VFile *file;
	if ( (fFileSystem == NULL) || tmpPath.IsChildOf( fFileSystem->GetRoot()) )
		file = new VFile(tmpPath, fFileSystem);
	else
		file = NULL;

	return file;
}
Exemplo n.º 12
0
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();
}
Exemplo n.º 13
0
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* VRIAServerSolution::RetainLogFolder( bool inCreateIfNotExists) const
{
	VFolder *folder = NULL;

	if (fDesignSolution != NULL)
	{
		VProjectItem *item = fDesignSolution->GetSolutionFileProjectItem();
		if (item != NULL)
		{
			VFilePath path;
			item->GetFilePath( path);
			path = path.ToFolder();
			path.ToSubFolder( L"Logs");
			folder = new VFolder( path);
			if (folder != NULL && !folder->Exists() && inCreateIfNotExists)
				folder->Create();
		}
	}
	return folder;
}
Exemplo n.º 15
0
VError VMacResFile::_Open(const VFilePath& inPath, FileAccess inFileAccess, Boolean inCreate)
{
	if (!testAssert(fRefNum == -1))
		return VE_STREAM_ALREADY_OPENED;
	
	assert(fLastStringList == NULL);
	
	fCloseFile = true;
	
	sWORD	curres = ::CurResFile();
	
	FSSpec spec;
	VString fullPath;
	inPath.GetPath(fullPath);
	Boolean isOk = XMacFile::HFSPathToFSSpec(fullPath, &spec) == noErr;

	SignedByte permission = fsCurPerm;
	switch(inFileAccess)
	{
		case FA_READ:	permission = fsRdPerm; break;
		case FA_READ_WRITE:	permission = fsWrPerm; break;
		case FA_SHARED:	permission = fsRdWrShPerm; break;
	}

	if (!isOk && inCreate)
		::FSpCreateResFile(&spec, '????', '????', smSystemScript);

	// the resource file for component is private so... open it as orphan (m.c)
	OSErr err = ::FSpOpenOrphanResFile(&spec, permission,&fRefNum);

	if (fRefNum == -1 && inCreate)
	{
		// L.E. 17/02/00 le fichier peut exister mais sans res fork
		// pas FSpCreateResFile car on veut conserver type et createur
		::HCreateResFile(spec.vRefNum, spec.parID, spec.name);
		::FSpOpenOrphanResFile(&spec, permission,&fRefNum);
	}
	
	OSErr macError = ::ResError();
	
	::UseResFile(curres);

	assert(fRefNum != -1);

	if (fRefNum == -1)
		fReadOnly = true;
	else
	{
		sWORD	flags = ::GetResFileAttrs(fRefNum);
		fReadOnly = (inFileAccess == FA_READ) || ((flags & mapReadOnly) != 0);
	}
	
	return VErrorBase::NativeErrorToVError((VNativeError)macError);
}
bool VProjectItemFile::ConformsTo( const VString& inFileKindID) const
{
	bool result = false, done = false;

	if (fOwner != NULL)
	{
	#if 0	// sc 08/09/2011, optimization
		VFilePath path;
		if (fOwner->GetFilePath( path) && path.IsFile())
		{
			VFile file( path);
			if (file.Exists())
			{
				result = file.ConformsTo( inFileKindID);
				done = true;
			}
		}
	#endif

		if (!done)
		{
			VString extension;
			fOwner->GetExtension( extension);

			VFileKind *itemKind = VFileKindManager::Get()->RetainFirstFileKindMatchingWithExtension( extension);
			if (itemKind != NULL)
			{
				VFileKind *refKind = VFileKindManager::Get()->RetainFileKind( inFileKindID);
				if (refKind != NULL)
				{
					result = itemKind->ConformsTo( *refKind);
					ReleaseRefCountable( &refKind);
				}
				ReleaseRefCountable( &itemKind);
			}
		}
	}

	return result;
}
Exemplo n.º 17
0
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;
}
Exemplo n.º 18
0
VFolder* XWinLibrary::RetainFolder(const VFilePath &inPath, BundleFolderKind inKind) const
{
	VFolder *folder = NULL;
	if (inPath.IsFile())
	{
		switch( inKind)
		{
			case kBF_BUNDLE_FOLDER:					// The folder hosting the bundle
			case kBF_EXECUTABLE_FOLDER:				// The folder of executable file (platform related)
				{
					VFilePath parent = inPath;
					folder = new VFolder( parent.ToParent());
				}

			default:
				assert( false);
				break;
		}
	}
	else if (inPath.IsFolder())
	{
		switch( inKind)
		{
			case kBF_BUNDLE_FOLDER:					// The folder hosting the bundle
				{
					VFilePath parent = inPath;
					folder = new VFolder( parent/*.ToParent()*/);
					break;
				}

			case kBF_EXECUTABLE_FOLDER:				// The folder of executable file (platform related)
				{
					VFilePath executablePath;
					if (_BuildExecutablePath( inPath, executablePath))
					{
						folder = new VFolder( executablePath.ToFolder());
					}
					break;
				}

			case kBF_RESOURCES_FOLDER:				// The folder of main resources
				{
					VFilePath path = inPath;
					path.ToSubFolder( CVSTR("Contents")).ToSubFolder( CVSTR( "Resources"));
					folder = new VFolder( path);
					break;
				}

			case kBF_LOCALISED_RESOURCES_FOLDER:	// The folder of prefered localization
			case kBF_PLUGINS_FOLDER:				// The folder for bundle's plugins
			case kBF_PRIVATE_FRAMEWORKS_FOLDER:		// The folder for private frameworks
			case kBF_PRIVATE_SUPPORT_FOLDER:		// The folder for private support files
			default:
				assert( false);
				break;
		}
	}
	return folder;
}
Exemplo n.º 19
0
bool XMacSystem::SearchExecutablePath( const VString& inExecutableName, VFilePath& outPath)
{
	// first lookup in environment variables
	bool found = XBSDSystem::SearchExecutablePath( inExecutableName, outPath);
	
	// then ask launch services
	if (!found)
	{
		VString name( inExecutableName);
		
		if (!name.EndsWith( CVSTR( ".app")))
			name += CVSTR( ".app");
		
		CFURLRef cfAppUrl = NULL;
		CFStringRef cfName = name.MAC_RetainCFStringCopy();
		OSStatus status = LSFindApplicationForInfo( kLSUnknownCreator, NULL /* inBundleID */, cfName, NULL /* outFSRef */, &cfAppUrl);
		if (cfName != NULL)
			CFRelease( cfName);
			
		if (status == noErr)
		{
			if (testAssert( cfAppUrl != NULL))
			{
				CFStringRef cfPosixPath = ::CFURLCopyFileSystemPath( cfAppUrl, kCFURLPOSIXPathStyle);
				if (testAssert( cfPosixPath != NULL))
				{
					VString posixPath;
					posixPath.MAC_FromCFString( cfPosixPath);
					
					posixPath.Compose();
					
					// add an ending / because it's a bundle folder
					posixPath += "/";
					outPath.FromFullPath( posixPath, FPS_POSIX);
					
					found = true;
					::CFRelease( cfPosixPath);
				}
			}
		}

		if (cfAppUrl != NULL)
			CFRelease( cfAppUrl);
	}
	
	return found;
}
Exemplo n.º 20
0
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;
}
CUAGDirectory* VRIAServerSolution::_OpenUAGDirectory( VError& outError)
{
	outError = VE_OK;

	CUAGDirectory *directory = nil;

	CUAGManager *uag = VComponentManager::RetainComponentOfType<CUAGManager>();
	if (uag != NULL)
	{
		if (testAssert(fDesignSolution != NULL))
		{
			StUseLogger logger;
			VMicrosecondsCounter usCounter;

			VProjectItem *dirItem = fDesignSolution->GetProjectItemFromTag( kUAGDirectoryTag);
			if (dirItem != NULL)
			{
				VFilePath directoryPath;
				dirItem->GetFilePath( directoryPath);
			
				usCounter.Start();
				logger.Log( fLoggerID, eL4JML_Information, L"Opening the users and groups directory");
				
				VFile file( directoryPath);
				directory = uag->RetainDirectory( file, FA_READ_WRITE, NULL, NULL, &outError);
			}

			if (directory == NULL && outError == VE_OK)
			{
				VFilePath solpath;
				fDesignSolution->GetSolutionFilePath(solpath);
				solpath.SetExtension(RIAFileKind::kDirectoryFileExtension);
				VFile defaultDirFile(solpath);
				directory = uag->RetainDirectory( defaultDirFile, FA_READ_WRITE, NULL, NULL, &outError, NULL, true);
			}

			if (directory != NULL && outError == VE_OK)
			{
				// Create an "admin" user if needed

				CUAGGroup *adminGroup = directory->RetainSpecialGroup( CUAGDirectory::AdminGroup);
				CUAGGroup *debuggerGroup = directory->RetainSpecialGroup( CUAGDirectory::DebuggerGroup);

				if ((adminGroup != NULL) && (debuggerGroup != NULL))
				{
					StErrorContextInstaller errorContext( VE_UAG_USERNAME_DOES_NOT_EXIST, VE_OK);

					CUAGUser *adminUser = directory->RetainUser( L"admin");
					
					if (adminUser == NULL)
						adminUser = directory->AddOneUser( L"admin", L"", L"", outError);

					if ((outError == VE_OK) && (adminUser != NULL))
					{
						VUUID adminUserID, userID;
						adminUser->GetID( adminUserID);
						
						CUAGUserVector users;
						adminGroup->RetainUsers( users);

						bool hasAdminUser = false;
						for (CUAGUserVector::iterator userIter = users.begin() ; (userIter != users.end()) && !hasAdminUser ; ++userIter)
						{
							(*userIter)->GetID( userID);
							hasAdminUser = (adminUserID == userID);
						}

						if (!hasAdminUser)
							outError = adminUser->PutIntoGroup( adminGroup);

						if (outError == VE_OK)
						{
							users.clear();
							debuggerGroup->RetainUsers( users);

							hasAdminUser = false;
							for (CUAGUserVector::iterator userIter = users.begin() ; (userIter != users.end()) && !hasAdminUser ; ++userIter)
							{
								(*userIter)->GetID( userID);
								hasAdminUser = (adminUserID == userID);
							}

							if (!hasAdminUser)
								outError = adminUser->PutIntoGroup( debuggerGroup);
						}
					}
					ReleaseRefCountable( &adminUser);
				}
				QuickReleaseRefCountable( adminGroup);
				QuickReleaseRefCountable( debuggerGroup);
			}

			if (directory != NULL && outError == VE_OK)
			{
				VString logMsg;
				logMsg.Printf( "Users and groups directory opened (duration: %i ms)", usCounter.Stop()/1000);
				logger.Log( fLoggerID, eL4JML_Information, logMsg);
			}
		}
		uag->Release();
	}
	else
	{
		outError = ThrowError( VE_RIA_UAG_COMPONENT_NOT_FOUND);
	}
	return directory;
}
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;
}
Exemplo n.º 23
0
VError PathBuffer::Init(const VFilePath& inPath, Mode inMode)
{
    VString absPath=inPath.GetPath();

    return Init(absPath, inMode);
}
Exemplo n.º 24
0
VFolder *VProcess::RetainProductSystemFolder( ESystemFolderKind inSelector, bool inCreateFolderIfNotFound) const
{
	VFolder *folder = NULL;
	
	bool allUsers;
	bool useProductSubFolder;
	ESystemFolderKind currentUserFolder;
	switch( inSelector)
	{
		case eFK_UserDocuments:
		case eFK_Temporary:
			allUsers = true;
			useProductSubFolder = true;
			break;

		case eFK_CommonPreferences:
			currentUserFolder = eFK_UserPreferences;
			allUsers = true;
			useProductSubFolder = true;
			break;

		case eFK_CommonApplicationData:
			currentUserFolder = eFK_UserApplicationData;
			allUsers = true;
			useProductSubFolder = true;
			break;

		case eFK_CommonCache:
			currentUserFolder = eFK_UserCache;
			allUsers = true;
			useProductSubFolder = true;
			break;

		case eFK_UserPreferences:
		case eFK_UserApplicationData:
		case eFK_UserCache:
			allUsers = false;
			useProductSubFolder = true;
			break;
		
		default:
			allUsers = false;
			useProductSubFolder = false;
			break;
	}
	
	if (useProductSubFolder)
	{
		VFolder *parent = VFolder::RetainSystemFolder( inSelector, inCreateFolderIfNotFound);
		if (parent != NULL)
		{
			VError err;
			VString folderName;
			GetProductName( folderName);

			// accepte un alias
			VString aliasName( folderName);
			#if VERSIONWIN
			aliasName += ".lnk";
			#endif
			VFile aliasFile( *parent, aliasName);
			if (aliasFile.Exists() && aliasFile.IsAliasFile())
			{
				VFilePath target;
				err = aliasFile.ResolveAlias( target);
				if ( (err == VE_OK) && target.IsFolder() )
				{
					folder = new VFolder( target);
				}
			}

			if (folder == NULL)
			{
				folder = new VFolder( *parent, folderName);
			}
			
			if (!folder->Exists())
			{
				if (inCreateFolderIfNotFound)
				{
					if (allUsers)
					{
						// drop errors if we can retry in current user home directory
						StErrorContextInstaller context( false);
						err = folder->CreateRecursive( allUsers);
					}
					else
					{
						err = folder->CreateRecursive( allUsers);
					}
					if (err != VE_OK)
					{
						ReleaseRefCountable( &folder);
						
						// si on nous a demande de creer dans "all users", on ressaie dans le dossier de l'utilisateur courant
						if (allUsers)
						{
							folder = RetainProductSystemFolder( currentUserFolder, inCreateFolderIfNotFound);
						}
					}
				}
				else
				{
					ReleaseRefCountable( &folder);
				}
			}
		}

		ReleaseRefCountable( &parent);
	}
	else
	{
		folder = VFolder::RetainSystemFolder( inSelector, inCreateFolderIfNotFound);
	}

	return folder;
}
// ---------------------------------------------------------------------------
// VComponentManager::RegisterComponentLibrary						[static]
// ---------------------------------------------------------------------------
// Load all component creators from a given library. Make sure that the
// library exports the VComponentLibrary interface.
//
VError VComponentManager::RegisterComponentLibrary( const VFilePath& inLibraryFile)
{
	DebugMsg("VComponentManager load %V\n", &inLibraryFile.GetPath());
	if (!IsInitialized())
		return vThrowError(VE_COMP_UNITIALISED);
	
	VError	error = VE_OK;
	
	VLibrary*	library;
	VArrayIteratorOf<VLibrary*>	iterator(*sComponentLibraries);
	
	// Iterate through libraries
	while ((library = iterator.Next()) != NULL)
	{
		if (library->IsSameFile(inLibraryFile))
		{
			error = vThrowError(VE_COMP_ALLREADY_REGISTRED);
			break;
		}
	}
	
	if (library == NULL)
	{
		library = new VLibrary(inLibraryFile);
		
		if (library != NULL)
		{
			if (!library->Load())
			{
				error = vThrowError(VE_COMP_CANNOT_LOAD_LIBRARY);
				library->Release();
				library = NULL;
			}
		}
		
		if (library != NULL)
		{
			// Make sure the library export the needed interface
			MainProcPtr	mainPtr = (MainProcPtr) library->GetProcAddress(kDEFAULT_MAIN_SYMBOL);
			GetNthComponentTypeProcPtr	fetchPtr = (GetNthComponentTypeProcPtr) library->GetProcAddress(kDEFAULT_GET_TYPES_SYMBOL);
			CreateComponentProcPtr	creatorPtr = (CreateComponentProcPtr) library->GetProcAddress(kDEFAULT_CREATE_SYMBOL);
			
			// Fetch all implemented components
			if (creatorPtr != NULL && fetchPtr != NULL && mainPtr != NULL)
			{
				sAccessingTypes->Lock();
				sAccessingChecked->Lock();
				
				(mainPtr)(kDLL_EVENT_REGISTER, library);
					
				CType	newType;
				sLONG	index = 1;
				while ((fetchPtr)(index, newType))
				{
					VIndex	oldPos = sComponentTypes->FindPos(newType);
					if (oldPos > 0)
					{
						// Assumes its allready installed using ProcPtr
						assert(sComponentProcs->GetNth(oldPos) != NULL);
						assert(sComponentLibraries->GetNth(oldPos) == NULL);
						
						sComponentLibraries->SetNth(library, oldPos);
					}
					else
					{
						// Add entries
						sComponentLibraries->AddTail(library);
						sComponentProcs->AddTail(NULL);
						sComponentTypes->AddTail(newType);
					}
					
					// Increment library refcount for each type
					library->Retain();
					
					index++;
		
					// Reset checking for unavailable components
					ResetComponentRequirements(newType, false);
				}
				
				sAccessingChecked->Unlock();
				sAccessingTypes->Unlock();
			}
			else
			{
				error = VE_COMP_BAD_LIBRARY_TYPE;
			}
			
			// Release library ('new' balance)
			library->Release();
		}
		else
		{
			error = VE_MEMORY_FULL;
		}
	}
	
	return error;
}
Exemplo n.º 26
0
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;	
}
Exemplo n.º 27
0
int main (int inArgc, char * const inArgv[])
{
	// set pattern matching wild char asap
	VCollator::SetDefaultWildChar( '*');	
	
	// First, create the application. So, everything is initialized and ready to use
	VRIAServerApplication application;
	VProcess::InitOptions initOptions = VProcess::Init_Default & ~VProcess::Init_WithQuickTime;

#if VERSION_LINUX
	XBOX::VString versionString;
	versionString.FromCString (STRPRODUCTVER); // 	YT 18-May-2012 - WAK0076647
    VRIAServerApplication::Get()->SetProductVersion (versionString);
#endif
	
    //jmo - We may want to quit after parsing the command line
    bool shouldQuit=false;

	if (application.Init( initOptions))
	{
		// Parse the command line argument
		VError err = VE_OK;

		// remote admin: feature development in progress
		//VRIAServerSupervisor*	srvSup = VRIAServerSupervisor::Get();

		VRIAServerStartupParameters *startupParameters = new VRIAServerStartupParameters();
		if (startupParameters != NULL)
		{
			// skip first argument (executable path)
			if (inArgc > 1)
			{
				int curArg = 1;

				while (curArg < inArgc && err == VE_OK)
				{
					VString argument( inArgv[curArg]);

					if (argument.BeginsWith( kARG_ADMINISTRATOR_PORT))
					{
						++curArg;
						argument.Remove( 1, kARG_ADMINISTRATOR_PORT.GetLength());
						if (!argument.IsEmpty() && argument.GetUniChar(1) == '=')
						{
							argument.Remove( 1, 1);
							if (!argument.IsEmpty())
							{
								sLONG port = argument.GetLong();
								if (port > 0)
									startupParameters->SetAdministratorHttpPort( port);
								else
									err = VE_RIA_INVALID_COMMAND_LINE_ARGUMENTS;
							}
							else
							{
								err = VE_RIA_INVALID_COMMAND_LINE_ARGUMENTS;
							}
						}
						else
						{
							err = VE_RIA_INVALID_COMMAND_LINE_ARGUMENTS;
						}
					}
					else if (argument.BeginsWith( kARG_ADMINISTRATOR_SSL_PORT))
					{
						++curArg;
						argument.Remove( 1, kARG_ADMINISTRATOR_SSL_PORT.GetLength());
						if (!argument.IsEmpty() && argument.GetUniChar(1) == '=')
						{
							argument.Remove( 1, 1);
							if (!argument.IsEmpty())
							{
								sLONG port = argument.GetLong();
								if (port > 0)
									startupParameters->SetAdministratorSSLPort( port);
								else
									err = VE_RIA_INVALID_COMMAND_LINE_ARGUMENTS;
							}
							else
							{
								err = VE_RIA_INVALID_COMMAND_LINE_ARGUMENTS;
							}
						}
						else
						{
							err = VE_RIA_INVALID_COMMAND_LINE_ARGUMENTS;
						}
					}
                    else if (argument.BeginsWith( kVERSION_NUMBER))
					{
						++curArg;
						argument.Remove(1, kVERSION_NUMBER.GetLength());

						VString version;
						
						VRIAServerApplication::Get()->GetProductVersion(version);
						
						char buf[100];
						
						version.ToCString(buf, sizeof(buf));
						
                        printf("Wakanda Server %s\n", buf);

                        shouldQuit=true;
					}
					else if (argument.BeginsWith( kLOG_DUMP))
					{
						++curArg;
						argument.Remove(1, kLOG_DUMP.GetLength());
						
						startupParameters->SetNetDump(true);
					}
					else if (argument.EqualToString( kARG_DEBUG_OFF))
					{
						++curArg;
						startupParameters->SetDebuggingAuthorized( false);
					}
					else if (argument.EqualToString( kARG_SYSLOG))
					{
						++curArg;

					#if VERSIONMAC || VERSION_LINUX
						VSysLogOutput *syslogOutput = new VSysLogOutput( L"Wakanda Server");
						application.GetLogger()->AddLogListener( syslogOutput);
						syslogOutput->Release();
					#endif
					}
					else
					{
						++curArg;

						// check whether it's a solution file path
						VFilePath fullPath;
					#if VERSIONWIN
						fullPath.FromFullPath( argument, FPS_SYSTEM);
					#else // VERSIONMAC
						VURL::Decode( argument);
						fullPath.FromFullPath( argument, FPS_POSIX);
					#endif

						if (fullPath.IsValid())
						{
							VFile *file = new VFile( fullPath);
							if (file != NULL)
							{
								if (file->Exists())
								{
									if (file->ConformsTo( RIAFileKind::kSolutionFileKind) && (startupParameters->GetSolutionToLaunch() == NULL))
									{
										startupParameters->SetSolutionToLaunch( file);
									}
									else if (file->ConformsTo( L"com.netscape.javascript-source") && (startupParameters->GetJavaScriptFileToExecute() == NULL))
									{
										startupParameters->SetJavaScriptFileToExecute( file);
									}
								}
							}
							else
							{
								err = VE_MEMORY_FULL;
							}
							ReleaseRefCountable( &file);
						}
						
						// Skip unknown argument without generate an error
					}
				}
			}

			if (err == VE_OK && shouldQuit == false)
			{
				VRIAServerStartupMessage *msg = new VRIAServerStartupMessage( &application, startupParameters);
				if (msg != NULL)
				{
					msg->PostTo( VTaskMgr::Get()->GetMainTask());
					msg->Release();
				}
				ReleaseRefCountable( &startupParameters);
				
				application.Run();
			}
			else
			{
				ReleaseRefCountable( &startupParameters);
			}
		}
	}
	return 0;
}