An error occurred in script '/home/yhr1ef23xez5/public_html/web2/app/model/bannerhit.php' on line 17:
Undefined index: HTTP_REFERER

    [type] => solution
    [name] => bp-VirtualFileSystem

WinWrap® | Virtual File System
logo WinWrap®

Virtual File System

WinWrap® Basic is an embedded macro language component available for .NET and COM 32/64 bit Windows applications. The WinWrap® Basic Component is an alternative to Visual Basic for Applications (VBA), ActiveX (e.g. VBScript, JScript, PerlScript, Rexx-based WSH engines and others), and VSTA for this purpose. The WinWrap® Basic Component is compatible with VBA, Sax Basic, VB.NET and Visual Basic 6.0 style scripts.

Virtual File System for Scripts

  • Use a database as the script storage system.
  • Protect real files when using Sandboxed mode.
  • Virtualize script names by context.
  • Only used for script names that don't begin with '*'.

Virtual File System

Using Implements to Extend the WinWrap Basic Scripting Language

Reading and writing files is a convenient feature, however, there are times when accessing the local file system in not desirable. In that case your application can redefine how the scripts are stored. In essence the VirtualFileSystem is merely a wrapper for file actions. This allows the "name" of script to be uncoupled from the "name" of the file. Of course, a complete uncoupling from the file system is possible. The virtual file system does not affect how script names starting with '*' are handled.

Implement the IVirtualFileSystem

The following implementation of IVirtualFileSystem treats script names as simple names. Simple names are translated into full path names in the virtual file system implementation. This is a useful approach for virtualizing storage location within the actual file system.

public class MyFileSystem : WinWrap.Basic.IVirtualFileSystem { private string rootDir = Path.GetFullPath(@"........Scripts"); public string Combine(string baseScriptPath, string name) { // ignore baseScriptPath in this example // all scripts are in the same "directory" return name; } public void Delete(string scriptPath) { File.Delete(ActualFileName(scriptPath)); } public bool Exists(string scriptPath) { return File.Exists(ActualFileName(scriptPath)); } public string GetCaption(string scriptPath) { return scriptPath; } public DateTime GetTimeStamp(string scriptPath) { return File.GetLastWriteTimeUtc(ActualFileName(scriptPath)); } public string Read(string scriptPath) { return File.ReadAllText(ActualFileName(scriptPath)); } public void Write(string scriptPath, string text) { File.WriteAllText(ActualFileName(scriptPath), text, System.Text.Encoding.UTF8); } private string ActualFileName(string scriptPath) { return Path.Combine(rootDir, scriptPath); } }

Implement the GetMacroName Event

The File Open and Save As menu choices request a file name from the user. If the file system is virtualized then GetMacroName event must be implemented also.

private void basicIdeCtl1_GetMacroName(object sender, WinWrap.Basic.Classic.GetMacroNameEventArgs e) { FileDialogForm dialog = new FileDialogForm(); foreach (string script in Scripts) dialog.listBox1.Items.Add(script); dialog.listBox1.SelectedIndex = 0; dialog.Text = e.OpenDialog ? "Open" : "Save"; dialog.ShowDialog(this); if (dialog.DialogResult == System.Windows.Forms.DialogResult.OK) e.FileName = Scripts[dialog.listBox1.SelectedIndex] + ".bas"; e.Handled = true; }

Use a Database for Script Storage

With the virtual file system the host application can read and write scripts anywhere. A database table mapping script names to script contexts can be where scripts are stored.

Protect the Real File System

It can be important to isolate scripts from the rest of the real file system. When using Sandboxed true, virtualizing script storage completely away from the file system is desirable.

Virtual Script Names by Context

With the virtual file system script names can be "redirected" based on application context. For example, reading and writing scripts to the user's documents directory is easily achieved.

'*' Script Names

The virtual file system is only used for "real" script names. Names that begin with '*' are still handled by the ReadMacro and WriteMacro events.

See WinWrap Examples for instructions on how to download and run "Example 7 - Virtual File System".

Copyright Polar Engineering, Inc.