|
| 1 | +*! version 1.1.0 Matthew White 14mar2012 |
| 2 | +pr truecrypt |
| 3 | + vers 9 |
| 4 | + if c(os) != "Windows" { |
| 5 | + di as err "Stata for Windows required" |
| 6 | + ex 198 |
| 7 | + } |
| 8 | + syntax [anything(name=volume)], [Mount DISmount DRive(str) PROGdir(str)] |
| 9 | + |
| 10 | + ***Check syntax*** |
| 11 | + * Check strings. |
| 12 | + loc volume `volume' |
| 13 | + loc temp : subinstr loc volume `"""' "", count(loc dq) |
| 14 | + if `dq' { |
| 15 | + di as err `"filename cannot contain ""' |
| 16 | + ex 198 |
| 17 | + } |
| 18 | + foreach option in drive progdir { |
| 19 | + loc temp : subinstr loc `option' `"""' "", count(loc dq) |
| 20 | + if `dq' { |
| 21 | + di as err `"option `option'() cannot contain ""' |
| 22 | + ex 198 |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + * -mount-, -dismount- |
| 27 | + if "`mount'`dismount'" == "" loc mount mount |
| 28 | + else if "`mount'" != "" & "`dismount'" != "" { |
| 29 | + di as err "options mount and dismount are mutually exclusive" |
| 30 | + ex 198 |
| 31 | + } |
| 32 | + |
| 33 | + * -mount- options |
| 34 | + if "`mount'" != "" { |
| 35 | + * `volume' |
| 36 | + conf f "`volume'" |
| 37 | + } |
| 38 | + * -dismount- options |
| 39 | + else { |
| 40 | + * `volume' |
| 41 | + if "`volume'" != "" { |
| 42 | + di as err "option dismount: filename not allowed" |
| 43 | + ex 198 |
| 44 | + } |
| 45 | + |
| 46 | + * -drive- |
| 47 | + if "`drive'" == "" { |
| 48 | + di as err "option dismount must be specified with option drive" |
| 49 | + ex 198 |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + * -drive- |
| 54 | + if "`drive'" != "" { |
| 55 | + if !regexm("`drive'", "^[A-Za-z]:?$") { |
| 56 | + di as err "option drive(): invalid drive" |
| 57 | + ex 198 |
| 58 | + } |
| 59 | + else loc drive = regexr("`drive'", ":$", "") |
| 60 | + } |
| 61 | + |
| 62 | + * -progdir- |
| 63 | + if "`progdir'" == "" loc progdir C:\Program Files\TrueCrypt |
| 64 | + conf f "`progdir'\TrueCrypt.exe" |
| 65 | + |
| 66 | + * Check that the drive is available if -mount- or is mounted if -dismount-. |
| 67 | + mata: st_local("mounted", strofreal(direxists("`drive':"))) |
| 68 | + if "`mount'" != "" & `mounted' { |
| 69 | + di as err "mount: drive letter `drive' not available" |
| 70 | + ex 198 |
| 71 | + } |
| 72 | + else if "`dismount'" != "" & !`mounted' { |
| 73 | + di as err "dismount: no volume specified by drive letter `drive'" |
| 74 | + ex 198 |
| 75 | + } |
| 76 | + ***End*** |
| 77 | + |
| 78 | + * -mount- |
| 79 | + if "`mount'" != "" /// |
| 80 | + sh "`progdir'\TrueCrypt.exe" /v "`volume'" `=cond("`drive'" != "", "/l `drive'", "")' /q |
| 81 | + * -dismount- |
| 82 | + else /// |
| 83 | + sh "`progdir'\TrueCrypt.exe" /d `drive' /q |
| 84 | +end |
| 85 | + |
| 86 | +* Changes history |
| 87 | +* version 1.0.0 21feb2012 |
| 88 | +* version 1.1.0 14mar2012 |
| 89 | +* -progdir()- is optional |
| 90 | +* Syntax checks added |
0 commit comments