Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/Authorization/Authorization to Restore File
Function:
Required plugins for this example: MBS MacCF Plugin, MBS MacOSX Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/Authorization/Authorization to Restore File
This example is the version from Sun, 17th Mar 2012.
Project "Authorization to Restore File.rbp"
FileTypes
Filetype text
Filetype special/any
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() Install End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() dim f as FolderItem f=GetOpenFolderItem("special/any") if f<>nil then SetFlags f,iMode.text,iOwner.text,iGroup.text end if End EventHandler
End Control
Control StaticText4 Inherits Label
ControlInstance StaticText4 Inherits Label
End Control
Control iMode Inherits TextField
ControlInstance iMode Inherits TextField
End Control
Control StaticText5 Inherits Label
ControlInstance StaticText5 Inherits Label
End Control
Control iOwner Inherits TextField
ControlInstance iOwner Inherits TextField
End Control
Control StaticText6 Inherits Label
ControlInstance StaticText6 Inherits Label
End Control
Control iGroup Inherits TextField
ControlInstance iGroup Inherits TextField
End Control
Control StaticText7 Inherits Label
ControlInstance StaticText7 Inherits Label
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() dim f as FolderItem dim d as DarwinChmodMBS f=GetOpenFolderItem("special/any") if f<>Nil then d=new DarwinChmodMBS if d.stat(f.UnixpathMBS)=0 then iOwner.text=str(d.uid) iGroup.text=str(d.gid) iMode.text=oct(d.mode) else MsgBox "Failed to do stat!" end if end if End EventHandler
End Control
Sub Install() dim s(-1) as String dim pTool,pScript,t as String dim f,dir as FolderItem dim a as AuthorizationMBS dim e as integer dim b as BinaryStream dim sh as Shell // write shell script file: dir=SpecialFolder.Desktop 'CreateApplicationSupportFolderMBS(-32763) if dir=nil then MsgBox "Missing Application Support folder in user directory." else f=dir.Child("FileFlagSetter") b=f.CreateBinaryFile("text") if b=nil then MsgBox "Failed to create tool file." else b.Write FileFlagSetter b.Close b=nil 'MsgBox f.AbsolutePath pTool=ShellPath(f) if pTool="" then MsgBox "Can't find the path to my tool." else 'MsgBox "chmod 777 "+pTool sh=new Shell sh.Execute "chmod 777 "+pTool if sh.ErrorCode<>0 then MsgBox "Failed to set permissions. "+str(sh.ErrorCode) else f=dir.Child("TestScript") b=f.CreateBinaryFile("text") if b=nil then MsgBox "Failed to create script file." else t=ConvertEncodingToUTF8(ScriptTemplates.StaticText1.text) t=ReplaceAll(t,"$",pTool) // change script t=ReplaceAll(t,EndOfLineMacintosh,EndOfLineUNIX) // line encodings are very important to avoid error -60031 b.Write t 'MsgBox t b.Close b=nil pScript=f.UnixpathMBS if pScript="" then MsgBox "Can't find the path to my script." else sh=new Shell 'MsgBox "chmod 777 "+ShellPath(f) sh.Execute "chmod 777 "+ShellPath(f) if sh.ErrorCode<>0 then MsgBox "Failed to set permissions. "+str(sh.ErrorCode) else a=new AuthorizationMBS if a.SimpleNewAuthorization then // create a.Execute(pScript,s,true) // and run it if a.LastError<>0 then MsgBox "Lasterror on Execute: "+str(a.LastError)+" "+pScript else e=a.Wait // wait for process to terminate. Returns PID if a.LastError<>0 then MsgBox "Lasterror on Wait: "+str(a.LastError) else MsgBox "Installed script." end if end if end if end if end if end if end if end if end if end if End Sub
Sub SetFlags(file as folderitem, Mode as string, User as string, Group as string) dim dir,f as FolderItem dim sh as Shell dim p(3) as String dim s as DarwinChmodMBS DIM I,C AS INTEGER // write shell script file: dir=SpecialFolder.Desktop'CreateApplicationSupportFolderMBS(-32763) if dir=nil then MsgBox "Missing Application Support folder in user directory." else f=dir.Child("FileFlagSetter") if f<>nil and f.Exists then sh=new Shell sh.Execute ShellPath(f)+" "+ShellPath(file)+" "+mode+" "+user+" "+Group MsgBox sh.Result s=new DarwinChmodMBS if s.stat(file.UnixpathMBS)=0 then StaticText7.text="File: "+file.UnixpathMBS+EndofLineMacintosh+"Mode: "+oct(s.mode)+EndofLineMacintosh+"Owner ID: "+str(s.uid)+EndofLineMacintosh+"Group ID: "+str(s.gid) else StaticText7.text="Failed to query new state." end if end if end if End Sub
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class ScriptTemplates Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
End Class
Module Util
Function ConvertEncodingToUTF8(s as string) As string ' in RB 5.x: ' return ConvertEncoding(s,encodings.utf8) dim t as TextConverter dim it,ot as TextEncoding it=GetTextEncoding(0) ot=GetTextEncoding(256,0,2) t=GetTextConverter(it,ot) Return t.convert(s) End Function
Function EndOfLineUNIX() As string ' in RB 5.x: ' return EndofLine.UNIX Return chrb(10) End Function
Function EndofLineMacintosh() As string ' in RB 5.x: ' return EndofLine.Macintosh1 Return chrb(13) End Function
Function ShellPath(f as folderitem) As string ' in RB 5.x: ' return f.shellpath dim s as string s=f.UnixpathMBS s=ReplaceAll(s,"\","\\") s=ReplaceAll(s," ","\ ") s=ReplaceAll(s,"|","\|") s=ReplaceAll(s,"&","\&") s=ReplaceAll(s,";","\;") s=ReplaceAll(s,"<","\<") s=ReplaceAll(s,">","\>") s=ReplaceAll(s,"(","\(") s=ReplaceAll(s,")","\)") s=ReplaceAll(s,"$","\$") s=ReplaceAll(s,"`","\`") s=ReplaceAll(s,"'","\'") s=ReplaceAll(s,"´","\´") // <-- CONVERTED s=ReplaceAll(s,"""","\""") s=ReplaceAll(s,chr(9),"\"+chr(9)) s=ReplaceAll(s,"*","\*") s=ReplaceAll(s,"?","\?") s=ReplaceAll(s,"[","\[") s=ReplaceAll(s,"#","\#") s=ReplaceAll(s,"~","\~") s=ReplaceAll(s,"=","\=") s=ReplaceAll(s,"%","\%") Return s End Function
End Module
ExternalFile FileFlagSetter
End ExternalFile
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS FileMaker tutorial videos