public void InitializeDatabase(Switch device) { _filesystemClient = device.FileSystem.FsClient; // Ensure we have valid data in the database _database.Format(); MountSave(); }
public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ContentType type) { if (type == ContentType.Meta) { return(ResultFs.InvalidArgument.Log()); } return(MountContent(fs, mountName, path, TitleId.Zero, type)); }
public static Result Register(this FileSystemClient fs, U8Span name, IFileSystem fileSystem, ICommonMountNameGenerator mountNameGenerator) { var accessor = new FileSystemAccessor(fs, name, null, fileSystem, mountNameGenerator, null); fs.Impl.Register(accessor); return(Result.Success); }
public void MountCacheStorage_CanMountCreatedCacheStorage() { var applicationId = new Ncm.ApplicationId(1); FileSystemClient fs = FileSystemServerFactory.CreateClient(true); fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, applicationId.Value, 0, 0, SaveDataFlags.None); Assert.Success(fs.MountCacheStorage("cache".ToU8Span(), applicationId)); }
//TODO consider removing this. public async Task <string> SetupFileSystemLeaseCondition(FileSystemClient fileSystem, string leaseId, string garbageLeaseId) { Models.DataLakeLease lease = null; if (leaseId == ReceivedLeaseId || leaseId == garbageLeaseId) { lease = await InstrumentClient(fileSystem.GetDataLakeLeaseClient(Recording.Random.NewGuid().ToString())).AcquireAsync(DataLakeLeaseClient.InfiniteLeaseDuration); } return(leaseId == ReceivedLeaseId ? lease.LeaseId : leaseId); }
/// <summary> /// Executes the performance test scenario synchronously. /// </summary> /// /// <param name="cancellationToken">The token used to signal when cancellation is requested.</param> /// public override void Run(CancellationToken cancellationToken) { var fileClient = FileSystemClient.GetFileClient(Path.GetRandomFileName()); Payload.Position = 0; fileClient.CreateIfNotExists(cancellationToken: cancellationToken); fileClient.Upload(Payload, true, cancellationToken); }
public FileAccessor(FileSystemClient fsClient, ref IFile file, FileSystemAccessor parentFileSystem, OpenMode mode) { FsClient = fsClient; _file = Shared.Move(ref file); _parentFileSystem = parentFileSystem; _openMode = mode; }
/// <summary> /// Executes the performance test scenario asynchronously. /// </summary> /// /// <param name="cancellationToken">The token used to signal when cancellation is requested.</param> /// public async override Task RunAsync(CancellationToken cancellationToken) { var fileClient = FileSystemClient.GetFileClient(Path.GetRandomFileName()); Payload.Position = 0; await fileClient.CreateAsync(cancellationToken : cancellationToken); await fileClient.UploadAsync(Payload, true, cancellationToken); }
public static Result DeleteSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId) { return(fs.RunOperationWithAccessLog(LocalAccessLogMode.System, () => { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); return fsProxy.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); }, () => $", savedataspaceid: {spaceId}, savedataid: 0x{saveDataId:X}")); }
public static Result IsArchivedProgram(this FileSystemClient fs, out bool isArchived, ProcessId processId) { using ReferenceCountedDisposable <IFileSystemProxyForLoader> fsProxy = fs.Impl.GetFileSystemProxyForLoaderServiceObject(); Result rc = fsProxy.Target.IsArchivedProgram(out isArchived, processId.Value); fs.Impl.AbortIfNeeded(rc); return(rc); }
public void SetSdCardAccessibility_SetAccessibilityPersists() { FileSystemClient fs = FileSystemServerFactory.CreateClient(false); fs.SetSdCardAccessibility(true); Assert.True(fs.IsSdCardAccessible()); fs.SetSdCardAccessibility(false); Assert.False(fs.IsSdCardAccessible()); }
public static Result DeleteSaveData(this FileSystemClient fs, ulong saveDataId) { return(fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); return fsProxy.DeleteSaveDataFileSystem(saveDataId); }, () => $", savedataid: 0x{saveDataId:X}")); }
public DirController(IDirService dirService, IConfiguration config) { this.config = config; this.dirService = dirService; var mongoClient = new MongoDB.Driver.MongoClient(config.GetConnectionString("MongoDbConnection")); var database = mongoClient.GetDatabase(nameof(WitDrive)); this.fsc = new FileSystemClient(database, chunkSize: 32768); this.space = long.Parse(config.GetSection("DiskSpace").GetSection("Space").Value); }
private GameTableContextMenu(Builder builder, ListStore gameTableStore, TreeIter rowIter, FileSystemClient fsClient) : base(builder.GetObject("_contextMenu").Handle) { builder.Autoconnect(this); _openSaveDir.Activated += OpenSaveDir_Clicked; _gameTableStore = gameTableStore; _rowIter = rowIter; _fsClient = fsClient; }
public AccountController(IEmailSender emailSender, UserManager <User> userManager, IConfiguration config) { this.emailSender = emailSender; this.userManager = userManager; var mongoClient = new MongoDB.Driver.MongoClient(config.GetConnectionString("MongoDbConnection")); var database = mongoClient.GetDatabase(nameof(WitDrive)); this.space = long.Parse(config.GetSection("DiskSpace").GetSection("Space").Value); this.fsc = new FileSystemClient(database, chunkSize: 32768); }
public static Result OpenDirectory(this FileSystemClient fs, out DirectoryHandle handle, U8Span path, OpenDirectoryMode mode) { UnsafeHelpers.SkipParamInit(out handle); Result rc; U8Span subPath; FileSystemAccessor fileSystem; Span <byte> logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"').Append(LogOpenMode).AppendFormat((int)mode, 'X'); logBuffer = sb.Buffer; fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); } else { rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } fs.Impl.AbortIfNeeded(rc); if (rc.IsFailure()) { return(rc); } DirectoryAccessor accessor; if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); rc = fileSystem.OpenDirectory(out accessor, subPath, mode); Tick end = fs.Hos.Os.GetSystemTick(); fs.Impl.OutputAccessLog(rc, start, end, accessor, new U8Span(logBuffer)); } else { rc = fileSystem.OpenDirectory(out accessor, subPath, mode); } fs.Impl.AbortIfNeeded(rc); if (rc.IsFailure()) { return(rc); } handle = new DirectoryHandle(accessor); return(Result.Success); }
private static Result ImportSave(FileSystemClient fs, SaveToImport save) { SaveDataAttribute key = save.Attribute; Result result = fs.CreateSaveData(key.TitleId, key.UserId, key.TitleId, 0, 0, 0); if (result.IsFailure()) { return(result); } bool isOldMounted = false; bool isNewMounted = false; try { result = fs.Register("OldSave".ToU8Span(), new LocalFileSystem(save.Path)); if (result.IsFailure()) { return(result); } isOldMounted = true; result = fs.MountSaveData("NewSave".ToU8Span(), key.TitleId, key.UserId); if (result.IsFailure()) { return(result); } isNewMounted = true; result = fs.CopyDirectory("OldSave:/", "NewSave:/"); if (result.IsFailure()) { return(result); } result = fs.Commit("NewSave"); } finally { if (isOldMounted) { fs.Unmount("OldSave"); } if (isNewMounted) { fs.Unmount("NewSave"); } } return(result); }
public virtual async Task <Response <FileSystemClient> > CreateFileSystemAsync( string fileSystemName, PublicAccessType publicAccessType = PublicAccessType.None, Metadata metadata = default, CancellationToken cancellationToken = default) { FileSystemClient fileSystem = GetFileSystemClient(fileSystemName); Response <FileSystemInfo> response = await fileSystem.CreateAsync(publicAccessType, metadata, cancellationToken).ConfigureAwait(false); return(Response.FromValue(fileSystem, response.GetRawResponse())); }
private Result OpenFileSystemClient(out FileSystemClient client) { if (FileSystemServer is null) { client = default; return(ResultLibHac.ServiceNotInitialized.Log()); } client = FileSystemServer.CreateFileSystemClient(); return(Result.Success); }
public async Task DeleteFileSystemAsync() { var name = GetNewFileSystemName(); DataLakeServiceClient service = GetServiceClient_SharedKey(); FileSystemClient fileSystem = InstrumentClient((await service.CreateFileSystemAsync(name)).Value); await service.DeleteFileSystemAsync(name); Assert.ThrowsAsync <RequestFailedException>( async() => await fileSystem.GetPropertiesAsync()); }
public static long GetTotalSize(FileSystemClient fs, U8Span path, string searchPattern = "*") { long size = 0; foreach (DirectoryEntryEx entry in fs.EnumerateEntries(path.ToString(), searchPattern)) { size += entry.Size; } return(size); }
public static Result GetEntryType(this FileSystemClient fs, out DirectoryEntryType type, U8Span path) { UnsafeHelpers.SkipParamInit(out type); Result rc; U8Span subPath; FileSystemAccessor fileSystem; Span <byte> logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append(LogEntryType) .Append(idString.ToString(AccessLogImpl.DereferenceOutValue(in type, rc))); logBuffer = sb.Buffer; fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); } else { rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } fs.Impl.AbortIfNeeded(rc); if (rc.IsFailure()) { return(rc); } if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); rc = fileSystem.GetEntryType(out type, subPath); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append(LogEntryType) .Append(idString.ToString(AccessLogImpl.DereferenceOutValue(in type, rc))); logBuffer = sb.Buffer; fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); } else { rc = fileSystem.GetEntryType(out type, subPath); } fs.Impl.AbortIfNeeded(rc); return(rc); }
internal FileSystemProxy(FileSystemProxyCore fsProxyCore, FileSystemClient fsClient, FileSystemServer fsServer) { FsProxyCore = fsProxyCore; FsClient = fsClient; FsServer = fsServer; CurrentProcess = -1; SaveDataSize = 0x2000000; SaveDataJournalSize = 0x1000000; AutoCreateSaveData = true; }
public static Result SetCurrentPosixTime(this FileSystemClient fs, Time.PosixTime currentPosixTime, int timeDifferenceSeconds) { using ReferenceCountedDisposable <IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.SetCurrentPosixTimeWithTimeDifference(currentPosixTime.Value, timeDifferenceSeconds); fs.Impl.AbortIfNeeded(rc); return(rc); }
public SaveDataIndexerManager(FileSystemClient fsClient, ulong saveDataId, MemoryResource memoryResource, IDeviceHandleManager sdCardHandleManager, bool isBisUserRedirectionEnabled) { FsClient = fsClient; SaveDataId = saveDataId; MemoryResource = memoryResource; _sdCardHandleManager = sdCardHandleManager; IsBisUserRedirectionEnabled = isBisUserRedirectionEnabled; _tempIndexer.Indexer = new SaveDataIndexerLite(); }
internal HorizonClient(Horizon horizon, ProcessId processId) { Horizon = horizon; ProcessId = processId; Fs = new FileSystemClient(this); Sm = new ServiceManagerClient(horizon.ServiceManager); Os = new OsClient(this); ArpLazy = new Lazy <ArpClient>(InitArpClient, true); }
public virtual Response <FileSystemClient> CreateFileSystem( string fileSystemName, PublicAccessType publicAccessType = PublicAccessType.None, Metadata metadata = default, CancellationToken cancellationToken = default) { FileSystemClient fileSystem = GetFileSystemClient(fileSystemName); Response <FileSystemInfo> response = fileSystem.Create(publicAccessType, metadata, cancellationToken); return(Response.FromValue(fileSystem, response.GetRawResponse())); }
public void InitializeDatabase(Switch device) { _filesystemClient = device.FileSystem.FsClient; // Ensure we have valid data in the database _database.Format(); // TODO: Unmount is currently not implemented properly at dispose, implement that and decrement MountCounter. MountCounter = 0; MountSave(); }
private static Result CopyDirectoryWithProgressInternal(FileSystemClient fs, U8Span sourcePath, U8Span destPath, CreateFileOptions options, IProgressReport logger) { string sourcePathStr = sourcePath.ToString(); string destPathStr = destPath.ToString(); Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath, OpenDirectoryMode.All); if (rc.IsFailure()) { return(rc); } using (sourceHandle) { foreach (DirectoryEntryEx entry in fs.EnumerateEntries(sourcePathStr, "*", SearchOptions.Default)) { string subSrcPath = PathTools.Normalize(PathTools.Combine(sourcePathStr, entry.Name)); string subDstPath = PathTools.Normalize(PathTools.Combine(destPathStr, entry.Name)); if (entry.Type == DirectoryEntryType.Directory) { fs.EnsureDirectoryExists(subDstPath); rc = CopyDirectoryWithProgressInternal(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), options, logger); if (rc.IsFailure()) { return(rc); } } if (entry.Type == DirectoryEntryType.File) { logger?.LogMessage(subSrcPath); rc = fs.CreateOrOverwriteFile(subDstPath, entry.Size, options); if (rc.IsFailure()) { return(rc); } rc = CopyFileWithProgress(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), logger); if (rc.IsFailure()) { return(rc); } } } } return(Result.Success); }
public void MountBis_MountUserPartition_OpensCorrectDirectory() { FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs); Assert.Success(fs.MountBis("user".ToU8Span(), BisPartitionId.User)); // Create a file in the opened file system Assert.Success(fs.CreateFile("user:/file".ToU8Span(), 0)); // Make sure the file exists on the root file system Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/user/file".ToU8Span())); Assert.Equal(DirectoryEntryType.File, type); }
//-------------------------------------------------------------------------------- //сохранение файла private void backgroundDownloader_DoWork(object sender, DoWorkEventArgs e) { MyFile file=(MyFile)e.Argument; using (FileStream output = new FileStream(file.Path, FileMode.Create)) { SinchronizeFileProgressInfo.ProgressBytes = 0; SinchronizeFileProgressInfo.ProgressProcent = 0; SinchronizeFileProgressInfo.Action = FileStatus.Download; using (FileSystemClient serverFileSystem = new FileSystemClient()) { StreamWithProgress fileSourceStream = new StreamWithProgress(serverFileSystem.GetFileStream(selectedFileId, Account.GetUserEmail(), Account.GetUserPass())); fileSourceStream.ProgressChanged += SetProgressInfoData; fileSourceStream.CopyTo(output); } } }
public ActionResult Copy(int fileId = 0, int outDirectoryId = 0, int isDirectory = 0) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); if (Request.HttpMethod == "POST") { try { FileSystemClient serverFileSystem = new FileSystemClient(); serverFileSystem.Copy(fileId, outDirectoryId, isDirectory, userEmail, userPassword); return Json(new { error = "", success = true, id = outDirectoryId }); } catch (Exception ex) { switch (ex.Message) { case "ParentIdIsNull": return Json(new { error = "Выберете каталог назначения!", success = false }); case "DirectoriesHaveSameIDs": return Json(new { error = "Скопировать директорию в саму себя нельзя!", success = false }); case "DirectoryMovedInItSelf": return Json(new { error = "Скопировать директорию в свою вложенную папку нельзя!", success = false }); default: return Json(new { error = ex.Message, success = false }); } } } ViewData["fileId"] = fileId; ViewData["isDirectory"] = isDirectory; ViewData["outDirectoryId"] = outDirectoryId; return View(); }
public ActionResult CreateDirectory(int directoryId=0, string name="") { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); if (Request.HttpMethod == "POST") { try { FileSystemClient serverFileSystem = new FileSystemClient(); MyFile directoryInfo = serverFileSystem.GetDirectory(directoryId, userEmail, userPassword); serverFileSystem.CreateDirectory(directoryInfo.Path + "\\" + name, userEmail, userPassword); return Json(new { error = "", success = true, id = directoryId }); } catch (Exception ex) { switch (ex.Message) { case "NameEmpty": return Json(new { error = "Введите имя директории!", success = false }); case "NameIsBusy": return Json(new { error = "Директория с таким именем уже существует!", success = false }); case "DirectoryNotFound": return RedirectToRoute("ShowFolder"); default: return Json(new { error = ex.Message, success = false }); } } } ViewData["directoryId"] = directoryId; return View(); }
public ActionResult ShowFolder(int id = 1) { string userEmail=(string)Session["email"]; string userPassword=(string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); try { FileSystemClient serverFileSystem = new FileSystemClient(); MyFile directoryInfo = serverFileSystem.GetDirectory(id, userEmail, userPassword); ViewData["currentPath"] = directoryInfo.Path; ViewData["currenId"] = id; ViewData["parentId"] = directoryInfo.ParentDirectoryId; ViewData["files"]= serverFileSystem.GetDirectoryFiles(id, false, userEmail, userPassword); } catch (Exception) { return RedirectToRoute("ShowFolder"); } return View(); }
public ActionResult DownloadFile(int id, string name) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); FileSystemClient serverFileSystem = new FileSystemClient(); try { return File(serverFileSystem.GetFileStream(id, userEmail, userPassword), "application/octet-stream", name); } catch (Exception) { return RedirectToRoute("UserEvents"); } }
public ActionResult Rename(int fileId , int isDirectory , string name="") { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); FileSystemClient serverFileSystem = new FileSystemClient(); MyFile fileInfo; if (isDirectory == 1) fileInfo = serverFileSystem.GetDirectory(fileId, userEmail, userPassword); else fileInfo = serverFileSystem.GetFile(fileId, userEmail, userPassword); if (Request.HttpMethod == "POST") { try { serverFileSystem.Rename(fileId, name, isDirectory, userEmail, userPassword); return Json(new { error = "", success = true, id = fileInfo.ParentDirectoryId }); } catch (Exception ex) { switch (ex.Message) { case "FileNotSelected": return Json(new { error = isDirectory == 1 ? "Выберите директорию для переименования!" : "Выберите файл для переименования", success = false }); case "EmptyNewName": return Json(new { error = isDirectory == 1 ? "Введите новое имя директории!" : "Введите новое имя файла", success = false }); case "FileNotExist": return Json(new { error = isDirectory == 1 ? "Такой директории не существует!" : "Такой файл не существует!", success = false }); case "NameIsBusy": return Json(new { error = isDirectory == 1 ? "Директория с таким именем уже существует!" : "Файл с таким именем уже существует!!", success = false }); default: return Json(new { error = ex.Message, success = false }); } } } ViewData["fileId"] = fileId; ViewData["name"] = fileInfo.Name; ViewData["isDirectory"] = isDirectory; return View(); }
public ActionResult Delete(int fileId , int isDirectory) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); FileSystemClient serverFileSystem = new FileSystemClient(); MyFile fileInfo; if(isDirectory==1) { fileInfo = serverFileSystem.GetDirectory(fileId, userEmail, userPassword); serverFileSystem.DeleteDirectory(fileId, userEmail, userPassword); } else { fileInfo = serverFileSystem.GetFile(fileId, userEmail, userPassword); serverFileSystem.DeleteFile(fileId, userEmail, userPassword); } return RedirectToRoute("ShowFolder", new { id = fileInfo.ParentDirectoryId }); }
public void Init() { string ServerRemoteAddress = "http://" + Properties.Settings.Default.ServerRemoteAddress + "/FileSystem/"; serverFileSystem = new FileSystemClient("BasicHttpBinding_IFileSystem", new EndpointAddress(ServerRemoteAddress)); }
public ActionResult GetTreeNode( string sleep, string mode,int key=0) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); if (mode == "baseFolders") key = 0; FileSystemClient serverFileSystem = new FileSystemClient(); DynaTreeNode[] subDirectories= serverFileSystem.GetDirectorySubDirectories(key, userEmail, userPassword); return Json(subDirectories, JsonRequestBehavior.AllowGet); }
public ActionResult Upload( int outDirectoryId) { string userEmail = (string)Session["email"]; string userPassword = (string)Session["password"]; if (userEmail == null || userPassword == null) return RedirectToRoute("Logout"); if (Request.HttpMethod == "POST") { try { HttpPostedFileBase file = HttpContext.Request.Files["fileData"]; FileSystemClient serverFileSystem = new FileSystemClient(); MyFile directoryInfo = serverFileSystem.GetDirectory(outDirectoryId, userEmail, userPassword); serverFileSystem.UploadFile(new MyFile {SizeSpecified = true, Name = file.FileName, Size = file.ContentLength, Path = directoryInfo.Path }, userEmail, userPassword, file.InputStream); return Json(new { error = "", success = true, id = outDirectoryId }); } catch (Exception ex) { switch (ex.Message) { case "DirectoryNotExist": return Json(new { error = "Выберете каталог назначения!", success = false }); default: return Json(new { error = ex.Message, success = false }); } } } return View(); }