/// <summary> /// Function to remove all of the providers. /// </summary> public void UnloadAll() { try { if (Interlocked.Increment(ref _incVar) > 1) { return; } // Remove file system provider data. foreach (GorgonFileSystemProvider provider in this) { provider.OnUnload(); } ClearItems(); // Clear any left over items and reset to the root directory. Add the default folder file system provider. _fileSystem.Clear(); } finally { Interlocked.Decrement(ref _incVar); } }
/// <summary> /// Function to load the text into the file system. /// </summary> private void LoadText() { _fileSystem.Clear(); _fileSystem.Mount(Program.GetResourcePath(@"FolderSystem\")); // Load the original before we mount the write directory. byte[] textData = _fileSystem.ReadFile("/SomeText.txt"); _originalText = Encoding.UTF8.GetString(textData); // Set the write location to the users app data folder. _fileSystem.WriteLocation = _writePath; // Load the modified version. textData = _fileSystem.ReadFile("/SomeText.txt"); string modifiedText = Encoding.UTF8.GetString(textData); textDisplay.Text = string.Equals(modifiedText, _originalText) ? _originalText : modifiedText; }
/// <summary> /// Function to open the editor file. /// </summary> /// <param name="path">Path to the editor file.</param> public static void Open(string path) { var packFileSystem = new GorgonFileSystem(); FileChanged = false; // Add the new file system as a mount point. var plugIns = from plugIn in Gorgon.PlugIns where plugIn is GorgonFileSystemProviderPlugIn && !PlugIns.IsDisabled(plugIn) select plugIn; foreach (var plugIn in plugIns) { packFileSystem.Providers.LoadProvider(plugIn.Name); } if (!packFileSystem.Providers.Any(item => item.CanReadFile(path))) { throw new FileLoadException(string.Format(APIResources.GOREDIT_ERR_NO_READ_PROVIDERS, Path.GetFileName(path))); } packFileSystem.Mount(path); try { // Remove our previous scratch data. ResetFile(); // At this point we should have a clean scratch area, so all files will exist in the packed file. // Unpack the file structure so we can work with it. var directories = packFileSystem.FindDirectories("*", true); var files = packFileSystem.FindFiles("*", true); // Create our directories. foreach (var directory in directories) { ScratchArea.ScratchFiles.CreateDirectory(directory.FullPath); } // Copy our files. foreach (var file in files) { using (var inputStream = packFileSystem.OpenStream(file, false)) { using (var outputStream = ScratchArea.ScratchFiles.OpenStream(file.FullPath, true)) { inputStream.CopyTo(outputStream); } } } FilePath = string.Empty; Filename = Path.GetFileName(path); // Load the meta data if it exists. EditorMetaDataFile.Load(); // If we can't write the file, then leave the editor file path as blank. // If the file path is blank, then the Save As function will be triggered if we attempt to save so we // can save it in a format that we DO understand. This is of course assuming we have any plug-ins loaded // that will allow us to save. if (GetWriterPlugIn(path) != null) { FilePath = path; } } catch { // We have a problem, reset whatever changes we've made. ResetFile(); throw; } finally { // At this point we don't need this file system any more. We'll // be using our scratch system instead. packFileSystem.Clear(); } }