-
Notifications
You must be signed in to change notification settings - Fork 1
/
Install.m
152 lines (130 loc) · 3.82 KB
/
Install.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
(* LieLink automatic installer.*)
(* Check for MMA version. *)
General::mmaversion = "LieLink is incompatible with Mathematica `1`.";
If[System`$VersionNumber < 7.,
Message[General::mmaversion, IntegerPart @ System`$VersionNumber];
Abort[]
];
(* Load Rolf Mertig's package installer. *)
Import["https://packageinstaller.googlecode.com/hg/PackageInstaller/PackageInstaller.m"];
BeginPackage["LieLinkInstaller`"]
Begin["`Private`"]
(*************************************
* *
* Initialize variables *
* *
*************************************)
installVersion = "0.4.3";
zipURL =
StringJoin[
"https://github.com/teake/LieLink/releases/download/",
installVersion,
"/LieLink.",
installVersion,
".zip"
];
previousDir = FindFile["LieLink`"];
If[ previousDir =!= $Failed,
installDir = FileNameJoin @ Drop[FileNameSplit@FindFile["LieLink`"], -3],
installDir = FileNameJoin @ { $UserBaseDirectory, "Applications" }
];
(*************************************
* *
* Install functions *
* *
*************************************)
(* Present a popup-dialog before proceeding to install. *)
InstallLieLink[directory_String] :=
Switch[
InstallDialog @ directory
,
"OK",
DoInstall @ directory
,
"ChangeDir",
InstallLieLink @ SystemDialogInput[
"Directory",
directory,
WindowTitle -> "Choose base directory to install LieLink into"
]
,
"Cancel",
$Canceled
,
_,
Null
];
(* Does the actual installation. *)
DoInstall[directory_] :=
Module[
{
result
},
Print["Installing LieLink "<> installVersion <> " ..."];
RenameItem @ FileNameJoin @ {directory, "LieLink"};
result = PackageInstaller`InstallPackage[
zipURL,
Directory -> directory,
Print->False
];
If[ result === directory,
Print["Installation successful. Type \"<<LieLink`\" to load the package."],
Print["Installation unsuccessful."]
]
];
(* Generates the install dialog *)
InstallDialog[directory_String] :=
ChoiceDialog[
StringJoin @
{
"LieLink " <> installVersion,
" will be installed into the " <> InstallDirectoryString @ directory <> ".\n",
Sequence @@ If[ !MemberQ[$Path, FileNameJoin @ FileNameSplit @ directory],
"WARNING: this directory is not a member of $Path.\n",
{}
],
"Any existing versions will be backed up.\n",
"\nDo you want to continue?"
},
{ "OK" -> "OK", "Change directory" -> "ChangeDir", "Cancel" -> "Cancel" },
WindowTitle -> "LieLink installer"
]
(* Changes the directory to a nice string if possible. *)
InstallDirectoryString[directory_String] :=
Switch[
FileNameJoin @ FileNameSplit @ directory
,
FileNameJoin @ { $UserBaseDirectory, "Applications" },
"user directory for packages"
,
FileNameJoin @ { $BaseDirectory, "Applications" },
"system directory for packages"
,
_,
"directory " <> directory
];
(* Renames a file or folder "file.ext" to "file.ext_old",
or if that's taken, "file.ext_old1" etc. *)
RenameItem[file_?FileExistsQ, renameextension_String:"_old"] :=
Module[
{
newfile, existing, basenew
},
basenew = FileNameTake[file] <> renameextension;
existing = FileNameTake /@ FileNames[ basenew ~~ NumberString..., {ParentDirectory @ file} ];
newfile = basenew <> If[
Length @ existing == 0,
"",
ToString[ 1 + ( ToExpression[ StringDrop[ Last @ existing, StringLength @ basenew ] ] /. Null -> 0 ) ]
];
newfile = FileNameJoin @ { ParentDirectory @ file, newfile };
RenameFile[ file, newfile ]
];
(*************************************
* *
* The actual install *
* *
*************************************)
InstallLieLink @ installDir
End[]
EndPackage[]