Platforms to show: All Mac Windows Linux Cross-Platform

MacAliasMBS class   Deprecated

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Alias MBS MacClassic Plugin ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
This item is deprecated and should no longer be used. You can use CFBookmarkMBS module instead.
Gives access to Aliases on Mac.
Example
// Store the reference to a FolderItem in a Binary File

Dim alias as MacAliasMBS
dim t,f as FolderItem
Dim bf as BinaryStream, s as String
t=SpecialFolder.Desktop.Child("test")
bf = t.CreateBinaryFile("") // open your binary file here
f = SpecialFolder.Desktop // the FolderItem you want to save
alias = new MacAliasMBS
if alias.Create(nil, f) = 0 then
s = alias.GetRecord
bf.WriteLong LenB(s) // this saves the length of the record
bf.Write s // this saves the record itself
end
bf.Close

// Retrieve the reference to a FolderItem from a Binary File

dim l as Integer

t=SpecialFolder.Desktop.Child("test")
bf = t.OpenAsBinaryFile(false) // open your binary file here
alias = new MacAliasMBS
l = bf.ReadLong
alias.SetRecord bf.Read(l)
f = alias.Resolve(nil, alias.attemptMount)
if alias.needsUpdate then
if alias.Update(nil, f) = 1 then
// ... you might want to save the updated alias in your file here
end
end
// f now describes the FolderItem again.
// It may not be existing any more, however, so here's a check for that:
if not f.exists then
msgBox "oops! the file is not available any more. Select a new one, please"
//... let the user locate the file
end

This Plugin implements a new Class for handling Mac OS Alias Records.

AliasRecords are like FolderItems, but can be made persistent: You can convert a FolderItem into a AliasRecord and store that AliasRecord in a file (like your Preferences file). Later you can retrieve that information again and convert it back into a FolderItem.

AliasRecords also appear inside Alias Files, that are usually created by the Finder. The enclosed sample application (Alias Mgr Plugin Demo.π) shows how to create and resolve such Alias Files.

Additional Background Information
The purpose of the class is to store paths to files and/or folders between runs of a RB application.
To store a path to a file/folder in an RB app, currently your only option is to get the abolute path as a string, and store that string in a file, usually your preferences file.
However, there is problem with using this technique: If, between runs of your app, the user changes the path of the file by moving it, or by renaming the file or any of its parent folders (including the volume name), your app will fail to locate the file next time
it is looking for it.
Fortunately, at least in Mac OS, there is a solution to this, which helps you to track your files in such a case. This is done by using Alias Records: they are the basic data structure that is also used in Alias Files as created and used in the Finder.
This class attempts to give the flexibility of Alias Records to your RB apps.

The meaning of the Relative path
When no relative path is specified, then the file is only located by its folder hierarchy down to the root of the volume. However, if a relative path is given, then the file is optionally located relative to that point.
So, if you locate files relatively to some folder, like the folder your application is in, you should specify your app's folder as the relative path so that the target is even found easily when the user moved the whole folder including your app and its related files. This is even more important when using this Alias class under Windows than under Mac OS (if files are moved in Mac OS, they often still can be found even without the help of the original folder hierarchy, while this is not possible under Windows 9x).

For Mac OS X 10.6 or newer, please also check CFBookmarkMBS module.

  • property needsUpdate as boolean
  • 14 methods
    • method AliasInfo as AliasInfoMBS
    • method close
    • method Create(relPath as FolderItem, target as FolderItem, isDirectory as boolean = false) as Integer
    • method CreateAliasFromPath(targetPath as string, fromFilePath as String = "", isDirectory as boolean = false) as Integer
    • method CreateFSRef(relPath as memoryblock, target as memoryblock) as Integer
    • method CreateMinimal(target as FolderItem, isDirectory as boolean = false) as Integer
    • method CreateMinimalFSRef(target as memoryblock) as Integer
    • method GetRecord as String
    • method PathString as String
    • method Resolve(relPath as FolderItem, mode as Integer) as FolderItem
    • method SetRecord(record as String)
    • method TargetName as String
    • method Update(relPath as FolderItem, target as FolderItem) as Integer
    • method VolumeName as String
  • 12 constants

Constants

Constant Value Description
allVols 8 One of the constants to use in Resolve. search on multiple volumes
This is the old constant name used for compatibility to older Xojo code.
Use BitwiseOr or Bitwise.Or to combine this constants values.
attemptMount 1 One of the constants to use in Resolve. mount the volume automatically
This is the old constant name used for compatibility to older Xojo code.
Use BitwiseOr or Bitwise.Or to combine this constants values.
exhaustive &h200 One of the constants to use in Resolve. search further
This is the old constant name used for compatibility to older Xojo code.
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMMountVol 1 One of the constants to use in Resolve. mount the volume automatically
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMMultVols 8 One of the constants to use in Resolve. search on multiple volumes
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMNoUI 2 One of the constants to use in Resolve. no user interface allowed during resolution
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMSearch &h100 One of the constants to use in Resolve. search quickly
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMSearchMore &h200 One of the constants to use in Resolve. search further
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMSearchRelFirst &h400 One of the constants to use in Resolve. search target on a relative path first
Use BitwiseOr or Bitwise.Or to combine this constants values.
kARMTryFileIDFirst &h800 One of the constants to use in Resolve. search by file id before path
Use BitwiseOr or Bitwise.Or to combine this constants values.
noDialogs 2 One of the constants to use in Resolve. no user interface allowed during resolution
This is the old constant name used for compatibility to older Xojo code.
Use BitwiseOr or Bitwise.Or to combine this constants values.
relFirst &h400 One of the constants to use in Resolve. search target on a relative path first
This is the old constant name used for compatibility to older Xojo code.
Use BitwiseOr or Bitwise.Or to combine this constants values.

This class has no sub classes.

Some examples using this class:

Blog Entries

Release notes


The items on this page are in the following plugins: MBS MacClassic Plugin.


MAAttachedWindowMBS   -   MacFileOperationMBS


The biggest plugin in space...