-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTensorBasesInstaller.m
90 lines (72 loc) · 4.08 KB
/
TensorBasesInstaller.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
(* ::Package:: *)
(************************************************************************)
(* This file was generated automatically by the Mathematica front end. *)
(* It contains Initialization cells from a Notebook file, which *)
(* typically will have the same name as this file except ending in *)
(* ".nb" instead of ".m". *)
(* *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs. Doing so is equivalent *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end. *)
(* *)
(* DO NOT EDIT THIS FILE. This entire file is regenerated *)
(* automatically each time the parent Notebook file is saved in the *)
(* Mathematica front end. Any changes you make to this file will be *)
(* overwritten. *)
(************************************************************************)
(* ::Input::Initialization:: *)
TensorBases::allowinternetuse="You have forbidden Mathematica to access the internet. Either allow Mathematica to access the internet or download TensorBases from github manually.";
If[Not["AllowInternetUse" /. SystemInformation["Network"]],
Message[TensorBases::allowinternetuse];
Abort[];
];
(* just for backwards compatibility *)
If[ToString[Context[URLDownload]]=!="System`",
URLDownload=URLSave
];
(* ::Input::Initialization:: *)
TensorBasesRepositoryAddress="https://raw.githubusercontent.com/satfra/TensorBases/main/";
TensorBasesZipLocation=TensorBasesRepositoryAddress<>"TensorBases.zip";
TensorBasesInstallDir=FileNameJoin[{$UserBaseDirectory,"Applications"}];
(* ::Input::Initialization:: *)
TensorBasesInstaller::zipdownloadfailed="Download from "<>TensorBasesZipLocation<>" failed.";
TensorBasesInstaller::installationfailed="\nInstallation failed. Please read the error messages for more information!";
Print["Downloading TensorBases ..."];
TensorBasesArchive=FileNameJoin[{$TemporaryDirectory,"TensorBases.zip"}];
URLDownload[TensorBasesZipLocation,TensorBasesArchive]
tmpTensorBasesImport=Import[TensorBasesArchive];
If[tmpTensorBasesImport==="{\"error\":\"Not Found\"}"||tmpTensorBasesImport==="404: Not Found",
Message[TensorBasesInstaller::zipdownloadfailed];Abort[];
];
newVersionString=(List@@Import[TensorBasesArchive,FileNameJoin[{"TensorBases","PacletInfo.m"}]])[[1]]["Version"];
TensorBasesFiles=FileNameJoin[{TensorBasesInstallDir,#}]&/@Import[TensorBasesArchive];
TensorBasesFilesExist=FileExistsQ/@TensorBasesFiles;
TensorBasesExistingInstallation=Or@@TensorBasesFilesExist;
TensorBasesExistingPacletInfo=FileNameJoin[{TensorBasesInstallDir,"TensorBases","PacletInfo.m"}];
TensorBasesExistingVersionString=If[FileExistsQ[TensorBasesExistingPacletInfo],(List@@Import[TensorBasesArchive,FileNameJoin[{"TensorBases","PacletInfo.m"}]])[[1]]["Version"],"unknown"];
(* ::Input::Initialization:: *)
deleteExisting=False;
deleteExisting=If[TensorBasesExistingInstallation,
ChoiceDialog["The installer has found an existing TensorBases installation.
Do you want to overwrite the existing installation version "<>TensorBasesExistingVersionString<>" with version "<>newVersionString<>"?
Otherwise the installation will be aborted.",
WindowTitle->"TensorBases Installation",WindowSize->{Medium,All}],False];
If[deleteExisting,DeleteFile[Pick[TensorBasesFiles,TensorBasesFilesExist]]];
If[TensorBasesExistingInstallation&&deleteExisting===False,
(*abort installation*)
Print["TensorBases installation aborted."];,
(*install TensorBases*)
installationSuccess=Check[
ExtractArchive[TensorBasesArchive,TensorBasesInstallDir];
Get["TensorBases`"]
,$Failed];
If[installationSuccess===$Failed,
(*installation failed*)
Message[TensorBasesInstaller::installationfailed];,
(*installation successful*)
PacletDataRebuild[];
Print["Installation was successful."];
];
];
Quiet[DeleteFile[TensorBasesArchive]];