예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
    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;
            }
        }
    }
예제 #4
0
 public VirtualFileSystemParams(FileSystemMode mode = FileSystemMode.Default) : base(PathParser.GetInstance(FileSystemStyle.Linux), mode)
 {
 }
예제 #5
0
    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;
        }
    }
예제 #6
0
    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)
 {
 }
예제 #8
0
 public ViewFileSystemParams(FileSystem underlayFileSystem, PathParser pathParser, FileSystemMode mode = FileSystemMode.Default, bool disposeUnderlay = false) : base(pathParser, mode)
 {
     this.UnderlayFileSystem = underlayFileSystem;
     this.DisposeUnderlay    = disposeUnderlay;
 }
예제 #9
0
 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
 {
 }
예제 #11
0
 public RawDiskFileSystemParams(FileSystemMode mode = FileSystemMode.Default) : base(mode)
 {
 }
예제 #12
0
        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);
        }
예제 #13
0
 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
 {
 }
예제 #14
0
 public ViewFileSystemParams(FileSystem underlayFileSystem, PathParser pathParser, FileSystemMode mode = FileSystemMode.Default) : base(pathParser, mode)
 {
     this.UnderlayFileSystem = underlayFileSystem;
 }