|
| 1 | +$AddInName = "ACLib-AccUnit-Loader" |
| 2 | +$AddInFileName = "AccUnitLoader.accda" |
| 3 | +$MsgBoxTitle = "Update ACLib-AccUnit-Loader" |
| 4 | + |
| 5 | + |
| 6 | +function Get-SourceFileFullName { |
| 7 | + $ScriptLocation = Get-ScriptLocation |
| 8 | + $retVal = '' + $ScriptLocation + $AddInFileName |
| 9 | + $retVal |
| 10 | +} |
| 11 | + |
| 12 | +function Get-DestFileFullName { |
| 13 | + $AddInLocation = Get-AddInLocation |
| 14 | + $retVal = $AddInLocation + $AddInFileName |
| 15 | + $retVal |
| 16 | +} |
| 17 | + |
| 18 | +function Get-ScriptLocation { |
| 19 | + $retVal = '' + $PSScriptRoot + "\" |
| 20 | + $retVal |
| 21 | +} |
| 22 | + |
| 23 | +function Get-AddInLocation { |
| 24 | + $env:APPDATA + "\Microsoft\AddIns\" |
| 25 | +} |
| 26 | + |
| 27 | +function FileCopy { |
| 28 | + Param($SourceFilePath, $DestFilePath) |
| 29 | + Copy-Item $SourceFilePath -Destination $DestFilePath |
| 30 | + $true |
| 31 | +} |
| 32 | + |
| 33 | +function Delete-AddInFiles { |
| 34 | + |
| 35 | + $DestFile = Get-DestFileFullName |
| 36 | + $AddInLocation = Get-AddInLocation |
| 37 | + $tlbPath = "\lib\AccessCodeLib.AccUnit.tlb" |
| 38 | + $Tlbfile = $AddInLocation + $tlbPath |
| 39 | + |
| 40 | + # Remove-Item -Path $DestFile -Force |
| 41 | + # Remove-Item -Path $Tlbfile -Force |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +function CopyFileAndRunPrecompileProc { |
| 46 | + |
| 47 | + Param($SourceFilePath, $DestFilePath) |
| 48 | + |
| 49 | + [System.Windows.Forms.MessageBox]::Show($SourceFilePath, "SourceFilePath", 0) |
| 50 | + |
| 51 | + |
| 52 | + #Copy-Item -Path $SourceFilePath -Destination $DestFilePath |
| 53 | + |
| 54 | + $ret = Run-PrecompileProcedure $DestFilePath |
| 55 | + If ($ret -eq $true) { |
| 56 | + $true |
| 57 | + } |
| 58 | + else { |
| 59 | + $false |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +function CreateMde { |
| 64 | + Param($SourceFilePath, $DestFilePath) |
| 65 | + |
| 66 | + Delete-AddInFiles |
| 67 | + |
| 68 | + $FileToCompile = $DestFilePath + ".accdb" |
| 69 | + $copied = FileCopy $SourceFilePath $FileToCompile |
| 70 | + If ($copied -ne $true) { |
| 71 | + return |
| 72 | + } |
| 73 | + |
| 74 | + #$AccessApp = New-Object -ComObject Access.Application |
| 75 | + $ret = Run-PrecompileProcedure $FileToCompile |
| 76 | + If ($ret -ne $true) { |
| 77 | + return |
| 78 | + } |
| 79 | + |
| 80 | + return |
| 81 | + |
| 82 | + $AccessApp.SysCmd(603, ($FileToCompile), ($DestFilePath)) |
| 83 | + |
| 84 | + Remove-Item -Path $FileToCompile -Force |
| 85 | + |
| 86 | + $true |
| 87 | + |
| 88 | +} |
| 89 | + |
| 90 | +function Run-PrecompileProcedure { |
| 91 | + Param([string]$AccdbFilePath) |
| 92 | + |
| 93 | + $AccessApp = New-Object -ComObject Access.Application |
| 94 | + $AccessApp.Visible = $true |
| 95 | + |
| 96 | + $AccessApp.OpenCurrentDatabase("" + $AccdbFilePath) |
| 97 | + |
| 98 | + $RunMethod = "CheckAccUnitTypeLibFile" |
| 99 | + $AccessApp.Run($RunMethod) |
| 100 | + $AccessApp.CloseCurrentDatabase |
| 101 | + |
| 102 | + $true |
| 103 | + |
| 104 | +} |
| 105 | + |
| 106 | + |
| 107 | +####main |
| 108 | + |
| 109 | + |
| 110 | +$msg = "Before updating the add-in file, the add-in must not be loaded! |
| 111 | +For safety, close all Access instances." |
| 112 | + |
| 113 | +[System.Windows.Forms.MessageBox]::Show($msg, $MsgBoxTitle + ": Information", 0) |
| 114 | + |
| 115 | +$msg ="Should the add-in be used as a compiled file (accde)? |
| 116 | +(Add-In is compiled and copied to the Add-In directory.)" |
| 117 | + |
| 118 | +$msgRet = [System.Windows.Forms.MessageBox]::Show($msg, $MsgBoxTitle, 3) |
| 119 | + |
| 120 | +$AddInLocation = Get-AddInLocation |
| 121 | + |
| 122 | +switch ( $msgRet ) |
| 123 | +{ |
| 124 | + "Yes" { |
| 125 | + $AddInFileInstalled = $true # CreateMde(GetSourceFileFullName, GetDestFileFullName) |
| 126 | + |
| 127 | + If ( $AddInFileInstalled -eq $true ) { |
| 128 | + $CompletedMsg = "Add-In was compiled and saved in '" + $AddInLocation + "'." |
| 129 | + } |
| 130 | + Else { |
| 131 | + $CompletedMsg = "Error! Compiled file was not created." |
| 132 | + } |
| 133 | + |
| 134 | + } |
| 135 | + |
| 136 | + "No" { |
| 137 | + #Delete-AddInFiles |
| 138 | + $SourceFileFullName = Get-SourceFileFullName |
| 139 | + $DestFileFullName = Get-DestFileFullName |
| 140 | + $AddInFileInstalled = CopyFileAndRunPrecompileProc $SourceFileFullName $DestFileFullName |
| 141 | + If ( $AddInFileInstalled ) { |
| 142 | + $CompletedMsg = "Add-In was saved in '" + $AddInLocation + "'." |
| 143 | + } |
| 144 | + Else { |
| 145 | + $CompletedMsg = "Error! File was not copied." |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + default { |
| 150 | + return |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +[System.Windows.Forms.MessageBox]::Show($CompletedMsg, $MsgBoxTitle, 0) |
| 155 | + |
0 commit comments