public void ExtractAssets(string assetFileName, string targetFolder) { string fileExtension = Path.GetExtension(assetFileName).ToLowerInvariant(); // If the OS is windows use the native .NET zip extraction (we only support .zip for Windows). if (_systemOperations.IsOSPlatform(OSPlatform.Windows)) { if (fileExtension != Constants.ZipExtension) { throw new AssetExtractionFailedException($"Only Zip format is supported in Windows. Unable to extract {assetFileName}."); } if (Directory.Exists(targetFolder)) { Directory.Delete(targetFolder, true); } _systemOperations.ExtractToDirectory(assetFileName, targetFolder); } else { // If the OS is Linux, we need to extract files using Linux Command Line. if (!LinuxSupportedFileExtensions.Any(extension => assetFileName.EndsWith(extension, StringComparison.InvariantCultureIgnoreCase))) { throw new AssetExtractionFailedException($"Only Tar, Tar.gz and Zip formats are supported in Linux. Unable to extract {assetFileName}."); } _systemOperations.CreateDirectory(targetFolder); ProcessStartInfo processStartInfo = Path.GetExtension(assetFileName).ToLowerInvariant() == Constants.ZipExtension ? GetProcessStartInfoForZip(assetFileName, targetFolder) : GetProcessStartInfoForTarOrGZip(assetFileName, targetFolder); _logger.LogInformation($"Starting asset extraction with command arguments: {processStartInfo.Arguments}"); using (Process process = new Process()) { process.StartInfo = processStartInfo; (int exitCode, string stdOut, string stdErr) = _systemOperations.RunProcessWithStdCapture(process); if (!string.IsNullOrEmpty(stdOut)) { _logger.LogVerbose(stdOut); } if (!string.IsNullOrEmpty(stdErr)) { _logger.LogError(stdErr); } if (exitCode != 0) { throw new AssetExtractionFailedException($"Asset extraction for file {assetFileName} failed. Errors: {stdErr ?? string.Empty}"); } _systemOperations.SetUnixOwnerIfNeeded(targetFolder, true); } } }
public Task <SessionHostInfo> CreateAndStart(int instanceNumber, GameResourceDetails gameResourceDetails, ISessionHostManager sessionHostManager) { SessionHostsStartInfo sessionHostStartInfo = gameResourceDetails.SessionHostsStartInfo; string sessionHostUniqueId = Guid.NewGuid().ToString("D"); string logFolderPathOnVm = Path.Combine(_vmConfiguration.VmDirectories.GameLogsRootFolderVm, sessionHostUniqueId); _systemOperations.CreateDirectory(logFolderPathOnVm); ISessionHostConfiguration sessionHostConfiguration = new SessionHostProcessConfiguration(_vmConfiguration, _logger, _systemOperations, sessionHostStartInfo); string configFolderPathOnVm = _vmConfiguration.GetConfigRootFolderForSessionHost(instanceNumber); _systemOperations.CreateDirectory(configFolderPathOnVm); ProcessStartInfo processStartInfo = new ProcessStartInfo(); (string executableFileName, string arguments) = GetExecutableAndArguments(sessionHostStartInfo, instanceNumber); processStartInfo.FileName = executableFileName; processStartInfo.Arguments = arguments; processStartInfo.WorkingDirectory = sessionHostStartInfo.GameWorkingDirectory ?? Path.GetDirectoryName(executableFileName); processStartInfo.Environment.AddRange(sessionHostConfiguration.GetEnvironmentVariablesForSessionHost(instanceNumber, sessionHostUniqueId)); _logger.LogInformation($"Starting process for session host with instance number {instanceNumber} and process info: FileName - {executableFileName}, Args - {arguments}."); SessionHostInfo sessionHost = sessionHostManager.AddNewSessionHost(sessionHostUniqueId, sessionHostStartInfo.AssignmentId, instanceNumber, sessionHostUniqueId, SessionHostType.Process); sessionHostConfiguration.Create(instanceNumber, sessionHostUniqueId, GetVmAgentIpAddress(), _vmConfiguration, sessionHostUniqueId); try { string processId = _processWrapper.Start(processStartInfo).ToString(); sessionHostManager.UpdateSessionHostTypeSpecificId(sessionHostUniqueId, processId); _logger.LogInformation($"Started process for session host. Instance Number: {instanceNumber}, UniqueId: {sessionHostUniqueId}, ProcessId: {processId}"); } catch (Exception exception) { _logger.LogException($"Failed to start process based host with instance number {instanceNumber}", exception); sessionHostManager.RemoveSessionHost(sessionHostUniqueId); sessionHost = null; } return(Task.FromResult(sessionHost)); }