Example #1
0
        /// <summary>
        /// Loads the sprites used in secondary panels in TNH
        /// </summary>
        private void LoadPanelSprites(SetupStage stage)
        {
            IFileHandle file   = Source.Resources.GetFile("mag_dupe_background.png");
            Sprite      result = TNHTweakerUtils.LoadSprite(file);

            MagazinePanel.background = result;

            file   = Source.Resources.GetFile("ammo_purchase_background.png");
            result = TNHTweakerUtils.LoadSprite(file);
            AmmoPurchasePanel.background = result;

            file   = Source.Resources.GetFile("full_auto_background.png");
            result = TNHTweakerUtils.LoadSprite(file);
            FullAutoPanel.background = result;

            file   = Source.Resources.GetFile("fire_rate_background.png");
            result = TNHTweakerUtils.LoadSprite(file);
            FireRatePanel.background = result;

            file   = Source.Resources.GetFile("minus_icon.png");
            result = TNHTweakerUtils.LoadSprite(file);
            FireRatePanel.minusSprite = result;

            file   = Source.Resources.GetFile("plus_icon.png");
            result = TNHTweakerUtils.LoadSprite(file);
            FireRatePanel.plusSprite = result;
        }
Example #2
0
        public NtStatus Open(FileAccess access, FileShare share, FileMode mode, FileOptions options,
                             FileAttributes attributes,
                             out IFileHandle handle)
        {
            var readAccess = (access & DataWriteAccess) == 0;

            if (!Writable && !readAccess)
            {
                handle = null;
                return(DokanResult.AccessDenied);
            }


            if (Writable)
            {
                handle = new FileStreamFileHandle(this, RealPath, readAccess? System.IO.FileAccess.Read:System.IO.FileAccess.Write, share, mode, options);
                return(DokanResult.Success);
            }
            else
            {
                if (mode == FileMode.OpenOrCreate && !IsExists || mode != FileMode.Open)
                {
                    handle = null;
                    return(DokanResult.AccessDenied);
                }
                handle = new FileStreamFileHandle(this, RealPath, System.IO.FileAccess.Read, share, mode, options);
                return(DokanResult.Success);
            }
        }
Example #3
0
        protected Mod.Manifest ModManifestOf(IFileHandle file)
        {
            var obj = ImmediateReaders.Get <JObject>()(file);

            // Do early version checking before deserializing the whole object.
            const string propertyName = "require";
            var          property     = obj[propertyName];

            if (property is null)
            {
                throw new FormatException("Manifest must have a '" + propertyName + "' property that describes the version of Deli required.");
            }

            var require = property.ToObject <SemVersion?>();

            if (require is null)
            {
                throw new FormatException("The required Deli version must not be null.");
            }

            var deli = Bootstrap.Constants.Metadata.Version;

            if (!deli.Satisfies(require) &&
                !(deli.Major == 0 && deli.Minor == 4 && require.Major == 0 && require.Minor == 3)             // Allow 0.3.x mods to be use on 0.4.x
                )
            {
                throw new FormatException($"This mod is incompatible with the current version of Deli (required: {require}; current: {deli})");
            }

            return(obj.ToObject <Mod.Manifest>(Serializer) !);
        }
 public BlobStorageSyncManager(ILogger <BlobStorageSyncManager> logger, IFileHandle fileHandler, IBlobFileRepository blobFileRepository, IDirectory directory)
 {
     _logger             = logger;
     _fileHandler        = fileHandler;
     _blobFileRepository = blobFileRepository;
     _directory          = directory;
 }
Example #5
0
        public SearchResultItemViewModel(JadeCore.Search.ISearchResult result)
        {
            _result = result;

            StringBuilder sb = new StringBuilder();

            sb.Append(result.Location.Path.Str);
            sb.Append(" - ");
            
            JadeCore.ITextDocument doc = JadeCore.Services.Provider.WorkspaceController.DocumentCache.FindOrAdd(result.File);
            _file = doc.File;
            LineNum = doc.GetLineNumForOffset(result.Location.Offset);
            ISegment line = doc.GetLineForOffset(result.Location.Offset);
            if(line != null)
            {
                int column = result.Location.Offset - line.Offset + 1;
                sb.Append("(");
                sb.Append(LineNum);
                sb.Append(",");
                sb.Append(column);
                sb.Append(")");
                sb.Append(": ");
                sb.Append(doc.GetText(line).Trim());
            }
            _summary = sb.ToString();            
        }
Example #6
0
 private void OnFileCreated(IFileHandle file)
 {
     FileChangeEvent handler = FileCreated;
     if (handler != null)
     {
         handler(new FileChangeEventArgs(file, FileChangeType.Created));
     }
 }
Example #7
0
 /// <summary>
 /// Create the write stream from the file, if not null.
 /// </summary>
 private Stream CreateStrm(IFileHandle file)
 {
     if (file == null)
     {
         return(null);
     }
     return(file.CreateWriteStream());
 }
Example #8
0
 public ITextDocument Find(IFileHandle file)
 {
     ITextDocument result;
     if (!_cache.TryGetValue(file, out result))
     {
         return null;
     }
     return result;
 }
Example #9
0
        public PCFFile(IFileHandle path, bool memStream, PCFfileType fileType = PCFfileType.Unknown)
        {
            this.memStream = memStream;
            this.path      = path;
            this.fileType  = fileType;
            this.blockData = new Dictionary <PCFResourceType, DataBlockBase>();

            //This must exist in order for pcf file to work properly.
            this.indexBlock = new IndexBlock();
        }
Example #10
0
        public File(IFileHandle fileHandle)
        {
            if (fileHandle == null)
                throw new ArgumentNullException("fileHandle");

            FileHandle = fileHandle;

            endPosition = FileHandle.Length;
            FileStream = new AccessStream(this);
        }
Example #11
0
        private bool _loading; //used to supress text change events while document is loading

        public TextDocument(IFileHandle handle)
        {
            File = handle;
            _loaded = false;
            _avDoc = new ICSharpCode.AvalonEdit.Document.TextDocument();
            _avDoc.TextChanged += OnAvDocTextChanged;
            _avDoc.Changed += OnAvDocChanged;
            _modified = false;
            _version = 0;
        }
Example #12
0
 public FileController(IDownloadFileService downloadFileService, IAuthRepository authRepository,
                       IDataAccessService dataAccessService, IFileService fileService, IFileHandle fileHandle, ILoggerService loggerService)
 {
     _downloadFileService = downloadFileService;
     _authRepository      = authRepository;
     _dataAccessService   = dataAccessService;
     _fileService         = fileService;
     _fileHandle          = fileHandle;
     _loggerService       = loggerService;
 }
Example #13
0
        public ITextDocument FindOrAdd(IFileHandle file)
        {
            ITextDocument result;

            if(!_cache.TryGetValue(file, out result))
            {
                result = new TextDocument(file);
                _cache.Add(file, result);
            }
            return result;
        }
        /// <summary>
        /// Saves <paramref name="loader"/> to the specified <paramref name="file"/>.
        /// </summary>
        public static void SaveLoader(ILegacyDataLoader loader, IFileHandle file)
        {
            Contracts.CheckValue(loader, nameof(loader));
            Contracts.CheckValue(file, nameof(file));
            Contracts.CheckParam(file.CanWrite, nameof(file), "Must be writable");

            using (var stream = file.CreateWriteStream())
            {
                SaveLoader(loader, stream);
            }
        }
Example #15
0
        /// <summary>
        /// Saves <paramref name="loader"/> to the specified <paramref name="file"/>.
        /// </summary>
        public static void SaveLoader(IDataLoader loader, IFileHandle file)
        {
            Contracts.CheckValue(loader, nameof(loader));
            Contracts.CheckValue(file, nameof(file));
            Contracts.CheckParam(file.CanWrite, nameof(file), "Must be writable");

            using (var stream = file.CreateWriteStream())
                using (var rep = RepositoryWriter.CreateNew(stream))
                {
                    ModelSaveContext.SaveModel(rep, loader, ModelFileUtils.DirDataLoaderModel);
                    rep.Commit();
                }
        }
Example #16
0
        /// <summary>
        /// Loads a sprite from a file path. Solution found here: https://forum.unity.com/threads/generating-sprites-dynamically-from-png-or-jpeg-files-in-c.343735/
        /// </summary>
        /// <param name=""></param>
        /// <param name="pixelsPerUnit"></param>
        /// <returns></returns>
        public static Sprite LoadSprite(IFileHandle file)
        {
            Texture2D spriteTexture = LoadTexture(file);

            if (spriteTexture == null)
            {
                return(null);
            }
            Sprite sprite = Sprite.Create(spriteTexture, new Rect(0, 0, spriteTexture.width, spriteTexture.height), new Vector2(0, 0), 100f);

            sprite.name = file.Name;
            return(sprite);
        }
Example #17
0
        /// <summary>
        ///		Creates an instance of <see cref="TypedFileHandle{TReader,TOut}"/>
        /// </summary>
        /// <param name="handle">The raw handle to deserialize</param>
        /// <param name="reader">The reader responsible for deserialization</param>
        public TypedFileHandle(IFileHandle handle, TReader reader)
        {
            _handle = handle;

            Reader  = reader;
            IsAlive = handle.IsAlive;

            if (IsAlive)
            {
                handle.Updated += OnUpdate;
                handle.Deleted += OnDelete;
            }
        }
Example #18
0
        /// <summary>
        /// Save the model to the output path.
        /// The method saves the loader and the transformations of dataPipe and saves optionally predictor
        /// and command. It also uses featureColumn, if provided, to extract feature names.
        /// </summary>
        /// <param name="env">The host environment to use.</param>
        /// <param name="ch">The communication channel to use.</param>
        /// <param name="output">The output file handle.</param>
        /// <param name="predictor">The predictor.</param>
        /// <param name="data">The training examples.</param>
        /// <param name="command">The command string.</param>
        public static void SaveModel(IHostEnvironment env, IChannel ch, IFileHandle output,
                                     IPredictor predictor, RoleMappedData data, string command = null)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(ch, nameof(ch));
            ch.CheckParam(output != null && output.CanWrite, nameof(output));
            ch.CheckValueOrNull(predictor);
            ch.CheckValue(data, nameof(data));
            ch.CheckValueOrNull(command);

            using (var stream = output.CreateWriteStream())
                SaveModel(env, ch, stream, predictor, data, command);
        }
Example #19
0
        public virtual void AddFile(IFileHandle shape)
        {
            if (shape == null)
            {
                return;
            }

            T item = InternalAppendFile(shape.FileUrl);

            if (item != null)
            {
                shape.FileHandle = item.Id;
                shape.FileUrl    = item.Path;
            }
        }
Example #20
0
        public virtual void AddFile(IFileHandle shape, string targetFile, bool isLock)
        {
            if (shape == null)
            {
                return;
            }

            T item = InternalAppendFile(shape.FileUrl, targetFile);

            if (item != null)
            {
                shape.FileHandle = item.Id;
                shape.FileUrl    = item.Path;
                item.IsLock      = isLock;
            }
        }
Example #21
0
        private bool GetWritableFileHandle(IDokanFileInfo info, out IFileHandle fileHandle)
        {
            if (info.Context is IFileHandle handle)
            {
                if (handle.Writable)
                {
                    fileHandle = handle;
                    return(true);
                }

                fileHandle = layerService.UpdateWritable(handle);
                return(fileHandle != null);
            }

            fileHandle = null;
            return(false);
        }
Example #22
0
        public NtStatus Open(FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes,
                             out IFileHandle handle)
        {
            handle = null;
            switch (mode)
            {
            case FileMode.Open:
                return(directoryInfo.Exists ? DokanResult.Success : DokanResult.FileNotFound);

            case FileMode.CreateNew:
                if (directoryInfo.Exists)
                {
                    return(DokanResult.FileExists);
                }
                directoryInfo.Create();
                return(DokanResult.Success);
            }

            return(DokanResult.Success);
        }
        // In this case, we make an asset reader for our ExampleAsset.
        public static ExampleAsset ExampleAssetOf(IFileHandle file)
        {
            // Open a raw stream to the file
            using var raw = file.OpenRead();
            // Wrap it in a StreamReader, so we can read text
            using var text = new StreamReader(raw);

            // Iterate through each line in the file
            string?line;
            var    lineNumber = 0;

            while ((line = text.ReadLine()) != null)
            {
                const string selector = "> ";

                ++lineNumber;

                // Ignore all lines without the selector
                if (!line.StartsWith(selector))
                {
                    continue;
                }

                // Trim off the selector
                var selected = line.Substring(selector.Length);

                // Return the trimmed line
                return(new ExampleAsset
                {
                    Line = lineNumber,
                    Message = selected
                });
            }

            // Return an empty asset as a last resort
            return(new ExampleAsset
            {
                Line = 0,
                Message = string.Empty
            });
        }
Example #24
0
        /// <summary>
        /// Loads a texture2D from the sent file. Source: https://stackoverflow.com/questions/1080442/how-to-convert-an-stream-into-a-byte-in-c
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static Texture2D LoadTexture(IFileHandle file)
        {
            // Load a PNG or JPG file from disk to a Texture2D
            // Returns null if load fails

            Stream       fileStream = file.OpenRead();
            MemoryStream mem        = new MemoryStream();

            CopyStream(fileStream, mem);

            byte[] fileData = mem.ToArray();

            Texture2D tex2D = new Texture2D(2, 2);

            if (tex2D.LoadImage(fileData))
            {
                return(tex2D);
            }

            return(null);
        }
Example #25
0
        void OnFileLibraryRename(object sender, FileLibraryRenameMessage msg)
        {
            if (msg == null || msg.Item == null)
            {
                return;
            }
            ShapeType type = msg.Item.Type == LibraryType.Image ? ShapeType.Image : ShapeType.Video;

            foreach (var item in shapeControl.Document)
            {
                if (item == null || item.Type != type)
                {
                    continue;
                }
                IFileHandle file = item as IFileHandle;
                if (file == null || file.FileHandle != msg.Item.Id)
                {
                    continue;
                }
                file.FileUrl = msg.Item.Path;
            }
        }
Example #26
0
        public static void EnsureLegacyFolderExists(IFileHandle legacyManifest)
        {
            if (legacyManifest is null)
            {
                return;
            }

            var manifest = Path.Combine(Constants.LegacyLevelsDirectory, "manifest.json");

            if (File.Exists(manifest))
            {
                return;
            }
            Directory.CreateDirectory(Constants.LegacyLevelsDirectory);
            Directory.CreateDirectory(Path.Combine(Constants.LegacyLevelsDirectory, "TakeAndHold"));
            Directory.CreateDirectory(Path.Combine(Constants.LegacyLevelsDirectory, "Other"));

            var stream = legacyManifest.OpenRead();
            var buffer = new byte[stream.Length];

            stream.Read(buffer, 0, buffer.Length);
            File.WriteAllBytes(manifest, buffer);
        }
Example #27
0
        public List <IFileHandle> GetFileHandle(string handle, ShapeType type)
        {
            List <IFileHandle> result = new List <IFileHandle>();

            if (_layers == null || _layers.Count < 1)
            {
                return(result);
            }

            foreach (var layer in _layers)
            {
                if (layer == null || layer.Shape == null || layer.Shape.Type != type)
                {
                    continue;
                }
                IFileHandle tmp = layer.Shape as IFileHandle;
                if (tmp != null && tmp.FileHandle == handle)
                {
                    result.Add(tmp);
                }
            }
            return(result);
        }
Example #28
0
 public FileChangeEventArgs(IFileHandle handle, FileChangeType changeType)
 {
     Handle = handle;
     ChangeType = changeType;
 }
        public static void SaveDataView(IChannel ch, IDataSaver saver, IDataView view, IFileHandle file, bool keepHidden = false)
        {
            Contracts.CheckValue(ch, nameof(ch));
            ch.CheckValue(saver, nameof(saver));
            ch.CheckValue(view, nameof(view));
            ch.CheckValue(file, nameof(file));
            ch.CheckParam(file.CanWrite, nameof(file), "Cannot write to file");

            using (var stream = file.CreateWriteStream())
                SaveDataView(ch, saver, view, stream, keepHidden);
        }
Example #30
0
        public bool Save(IFileHandle file)
        {
            if (!_loaded || !_modified)
                return false;

            using (FileStream fs = new FileStream(file.Path.Str, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                using (StreamWriter writer = new StreamWriter(fs, System.Text.Encoding.ASCII))
                {
                    writer.Write(AvDoc.Text);
                    Modified = false;
                }
            }
            File = file;
            return true;
        }
Example #31
0
 public Displayer()
 {
     _show   = ServiceContext.Resolve <IShow>();
     _export = ServiceContext.Resolve <IFileHandle>();
 }
Example #32
0
 /// <summary>
 ///		Creates an instance of <see cref="DelayedTypedFileHandle{T}"/>
 /// </summary>
 /// <param name="handle">The raw file handle to deserialize</param>
 /// <param name="reader">The delayed reader responsible for deserialization</param>
 public DelayedTypedFileHandle(IFileHandle handle, DelayedReader <T> reader) : base(handle, reader)
 {
 }
Example #33
0
 public void Add(IFileHandle handle)
 {
     System.Diagnostics.Debug.Assert(Contains(handle) == false);
     _handles.Add(handle.Path, handle);
 }
Example #34
0
        public void SetInput(IHostEnvironment env, Experiment experiment)
        {
            IFileHandle inputFile = GetTextLoaderFileHandle(env, _inputFilePath);

            experiment.SetInput(ImportTextInput.InputFile, inputFile);
        }
Example #35
0
        public static UnityRootNode CreateNodeTree(Dictionary <PCFResourceType, DataBlockBase> dataBlocks, IFileHandle filePath, NodeFactory nodeFactory)
        {
            NodeBlock nodeBlock = dataBlocks[PCFResourceType.NODE] as NodeBlock;

            //Create and hook up node graph, but do no actual deserialization.
            UnityNodeBase node = nodeBlock.RecreateNodeGraph <UnityNodeBase>(nodeFactory);

            UnityRootNode rootNode = node as UnityRootNode;

            //Give rootnode a reference to the file we operate on, some nodes stream their data from this file.
            rootNode.SetFile(filePath);

            return(rootNode);
        }
Example #36
0
 public void SetFile(IFileHandle filePath)
 {
     this.filePath = filePath;
 }
 public FileHandleSource(IFileHandle file)
 {
     Contracts.CheckValue(file, nameof(file));
     Contracts.CheckParam(file.CanRead, nameof(file), "File handle must be readable");
     _file = file;
 }
Example #38
0
 public bool Contains(IFileHandle handle)
 {
     return Contains(handle.Path);
 }
Example #39
0
 internal IFileHandle UpdateWritable(IFileHandle handle)
 {
     throw new NotImplementedException();
 }
Example #40
0
 public OpenFileCommandParams(IFileHandle file, DisplayCodeLocationCommandParams displayParams)
 {
     File = file;
     DisplayParams = displayParams;
 }
Example #41
0
 public OpenFileCommandParams(IFileHandle file)
 {
     File = file;
     DisplayParams = new DisplayCodeLocationCommandParams(new CppCodeBrowser.CodeLocation(file.Path.Str, 0), true, true);
 }
Example #42
0
        public void OpenDocument(IFileHandle file)
        {
            lock (_lockObject)
            {
                if (_openDocuments.ContainsKey(file.Path) == false)
                {
                    IEditorDoc doc = null;

                    //find project?
                    ITextDocument textDoc = JadeCore.Services.Provider.WorkspaceController.DocumentCache.FindOrAdd(file);

                    Project.IProject p = GetProjectForFile(file.Path);
                    if (p != null)
                        CreateProjectBuilder(p);
                    doc = new SourceDocument(this, textDoc, p);
                    _openDocuments.Add(file.Path, doc);
                    OnDocumentOpened(doc);
                    ActiveDocument = doc;
                }

                //this doc is already open, if it's not the active document, activate it
                else if (ActiveDocument == null || ActiveDocument.File != file)
                {
                    ActiveDocument = _openDocuments[file.Path];
                }
            }
         }
Example #43
0
        public void OnOpenFile(IFileHandle handle)
        {
            if(handle == null)
                handle = JadeCore.GuiUtils.PromptOpenFile(".cs", "C# Source files (.cs)|*.cs", true);

            if (handle == null)
                return;

            try
            {
                _editorController.OpenDocument(handle);                
            }
            catch (Exception e)
            {
                JadeCore.GuiUtils.DisplayErrorAlert("Error opening file. " + e.ToString());
            }
        }
Example #44
0
 /// <summary>
 ///		Creates an instance of <see cref="ImmediateTypedFileHandle{T}"/>
 /// </summary>
 /// <param name="handle">The raw file handle to deserialize</param>
 /// <param name="reader">The immediate reader responsible for deserialization</param>
 public ImmediateTypedFileHandle(IFileHandle handle, ImmediateReader <T> reader) : base(handle, reader)
 {
 }
Example #45
0
 public bool Remove(IFileHandle handle)
 {
     return Remove(handle.Path);
 }