IFileManager CreateFileManager(Dictionary <string, SftpOptions> sftpOptions, FileSystemMode mode, string host) { switch (mode) { case FileSystemMode.Local: return(new LocalFileManager()); case FileSystemMode.SFTP: { if (sftpOptions.TryGetValue(host, out var options)) { var logger = LoggerFactory.CreateLogger <SftpFileManager>(); return(new SftpFileManager(options.Host, options.UserName, options.Password, logger)); } return(null); } default: return(null); } }
public FileSystemResultCode OpenContent(string filePath, FileSystemMode mode) { if (stream != null) { return(FileSystemResultCode.ContentHasBeenOpenedError); } FileMode fileMode; FileAccess fileAccess; FileShare fileShare; if (mode == FileSystemMode.Read) { fileMode = FileMode.Open; fileAccess = FileAccess.Read; fileShare = FileShare.Read; } else if (mode == FileSystemMode.Create) { fileMode = FileMode.Create; fileAccess = FileAccess.Write; fileShare = FileShare.None; } else if (mode == FileSystemMode.Update) { fileMode = FileMode.OpenOrCreate; fileAccess = FileAccess.ReadWrite; fileShare = FileShare.None; } else { return(FileSystemResultCode.ModeNotExistError); } try { stream = new FileStream(filePath, fileMode, fileAccess, fileShare); return(FileSystemResultCode.Success); } catch (Exception) { return(FileSystemResultCode.ContentOpenError); } }
public void Open(MapEditor parent, FileSystemMode mode) { gameObject.SetActive(true); mapEditor = parent; okButton.onClick.RemoveAllListeners(); if (mode == FileSystemMode.Save) { headLine.text = "Save"; okButtonText.text = "Save"; okButton.onClick.AddListener(() => Save(mapNameField)); } if (mode == FileSystemMode.Load) { headLine.text = "Load"; okButtonText.text = "Load"; okButton.onClick.AddListener(() => Load(mapNameField)); } if (mapListElements != null) { for (int i = 0; i < mapListElements.Length; i++) { Destroy(mapListElements[i].gameObject); } } Object[] mapObjects = Resources.LoadAll("Map"); mapListElements = new FileSystemElement[mapObjects.Length]; for (int i = 0; i < mapObjects.Length; i++) { if ((TextAsset)mapObjects[i] != null) { mapListElements[i] = Instantiate(mapListElementPrefab); mapListElements[i].transform.SetParent(scrollContent.transform); mapListElements[i].Init(this, mapObjects[i].name); } else { mapListElements[i] = null; } } }
public VirtualFileSystemParams(FileSystemMode mode = FileSystemMode.Default) : base(PathParser.GetInstance(FileSystemStyle.Linux), mode) { }
public LargeFileSystemParams(FileSystem underlayFileSystem, long maxSingleFileSize = -1, long logicalMaxSize = -1, string?splitStr = null, FileSystemMode mode = FileSystemMode.Default) : base(underlayFileSystem.PathParser, mode) { checked { if (maxSingleFileSize <= 0) { maxSingleFileSize = CoresConfig.LocalLargeFileSystemSettings.MaxSingleFileSize.Value; } if (logicalMaxSize <= 0) { logicalMaxSize = CoresConfig.LocalLargeFileSystemSettings.LogicalMaxSize.Value; } if (splitStr._IsEmpty()) { splitStr = CoresConfig.LocalLargeFileSystemSettings.SplitStr.Value; } this.UnderlayFileSystem = underlayFileSystem; this.SplitStr = splitStr._NonNullTrim()._FilledOrDefault("~~~"); this.MaxSinglePhysicalFileSize = Math.Min(Math.Max(maxSingleFileSize, 1), int.MaxValue); this.MaxLogicalFileSize = logicalMaxSize; long i = (this.MaxLogicalFileSize / this.MaxSinglePhysicalFileSize); i = Math.Max(i, 1); i = (int)Math.Log10(i); NumDigits = (int)i; this.MaxFileNumber = Str.MakeCharArray('9', NumDigits)._ToLong(); this.MaxLogicalFileSize = (MaxSinglePhysicalFileSize * (this.MaxFileNumber + 1)) - 1; } }
public ChrootFileSystemParam(FileSystem underlayFileSystem, string physicalRootDirectory, FileSystemMode mode = FileSystemMode.Default, bool disposeUnderlay = false) : base(underlayFileSystem, mode, disposeUnderlay) { physicalRootDirectory = underlayFileSystem.NormalizePath(physicalRootDirectory); physicalRootDirectory = underlayFileSystem.PathParser.NormalizeDirectorySeparatorAndCheckIfAbsolutePath(physicalRootDirectory); this.PhysicalRootDirectory = physicalRootDirectory; }
public Utf8BomFileSystemParam(FileSystem underlayFileSystem, FileSystemMode mode = FileSystemMode.Default) : base(underlayFileSystem, underlayFileSystem.PathParser, mode) { }
public ViewFileSystemParams(FileSystem underlayFileSystem, PathParser pathParser, FileSystemMode mode = FileSystemMode.Default, bool disposeUnderlay = false) : base(pathParser, mode) { this.UnderlayFileSystem = underlayFileSystem; this.DisposeUnderlay = disposeUnderlay; }
public Utf8BomFileSystemParam(FileSystem underlayFileSystem, FileSystemMode mode = FileSystemMode.Default, bool disposeUnderlay = false) : base(underlayFileSystem, underlayFileSystem.PathParser, mode, disposeUnderlay) { }
public RewriteViewFileSystemParam(FileSystem underlayFileSystem, FileSystemMode mode = FileSystemMode.Default) : base(underlayFileSystem, underlayFileSystem.PathParser.Style == FileSystemStyle.Windows ? PathParser.GetInstance(FileSystemStyle.Mac) : underlayFileSystem.PathParser, mode) // Use the Mac OS X path parser if the underlay file system is Windows { }
public RawDiskFileSystemParams(FileSystemMode mode = FileSystemMode.Default) : base(mode) { }
public FileSystemResultCode Open(FileSystemMode mode, string contentPath, string indexPath) { Mode = mode; ContentFilePath = contentPath; IndexFilePath = indexPath; if (Mode != FileSystemMode.Create && !File.Exists(ContentFilePath)) { return(FileSystemResultCode.ContentFileNotExistError); } if (Mode != FileSystemMode.Create && !File.Exists(IndexFilePath)) { return(FileSystemResultCode.IndexFileNotExistError); } content = new FileContent(); chunk = new FileChunk(); if (Mode != FileSystemMode.Read) { fragment = new FileFragment(); } FileSystemResultCode resultCode = FileSystemResultCode.Success; resultCode = content.OpenContent(ContentFilePath, Mode); if (resultCode == FileSystemResultCode.Success) { if (Mode != FileSystemMode.Create) { FileStream indexStream = null; try { indexStream = new FileStream(IndexFilePath, FileMode.Open, FileAccess.Read, FileShare.None); resultCode = chunk.ReadFromStream(indexStream); if (resultCode == FileSystemResultCode.Success && fragment != null) { resultCode = fragment.ReadFromStream(indexStream); } } catch { resultCode = FileSystemResultCode.IndexFileNotExistError; } finally { if (indexStream != null) { indexStream.Close(); } } } } if (resultCode != FileSystemResultCode.Success) { content.Close(); content = null; fragment = null; chunk = null; } return(resultCode); }
public RewriteFileSystemParam(FileSystem underlayFileSystem, FileSystemMode mode = FileSystemMode.Default, bool disposeUnderlay = false) : base(underlayFileSystem, underlayFileSystem.PathParser.Style == FileSystemStyle.Windows ? PathParser.GetInstance(FileSystemStyle.Mac) : underlayFileSystem.PathParser, mode, disposeUnderlay) // Use the Mac OS X path parser if the underlay file system is Windows { }
public ViewFileSystemParams(FileSystem underlayFileSystem, PathParser pathParser, FileSystemMode mode = FileSystemMode.Default) : base(pathParser, mode) { this.UnderlayFileSystem = underlayFileSystem; }