private UAReturn CheckAndInstallBlueSkyRPackage()
{
bool isinstalled = false;// package already installed
bool islatestinstalled = true; //already installed package is the latest version.
UAReturn res = new UAReturn() { Success = false };
//Get BlueSky R .zip package names and location
string BSkyMainPackagePath = string.Empty;//Main pacakge fullpathfilename.Assuming in future BlueSky R pacakge may break down in multiple R pacakges.
string[] RpackageFullPathFilenames = null;//for all BlueSky*.zip package names
string parentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace('\\', '/') + "/R Packages/BlueSky R Package(s)";
if (Directory.Exists(parentDir))
{
//find all the .zip file in RPacakges directory
RpackageFullPathFilenames = Directory.GetFiles(parentDir.Replace('/', '\\'), "BlueSky*.zip");//only look for packages with names "BlueSky*.zip"
BSkyMainPackagePath = Array.Find(RpackageFullPathFilenames, element => element.Contains("BlueSky_"));
}
//Now check if BlueSky R pacakge is already installed.
isinstalled = IsRPacakgeInstalled("BlueSky");
if (isinstalled) //if BlueSky R package is already installed then check the version
{
string existingVersion = rpm.GetInstalledPacakgeVersion("BlueSky");
string newVersion = string.Empty;
string pkgname = rpm.GetPackageNameFromZip(BSkyMainPackagePath, out newVersion);
if (rpm.CompareVersion(newVersion, existingVersion) == 1) //new version in BlueSky app and old is already installed
{
islatestinstalled = false; //latest not already installed.
}
}
//Install BlueSky R package(s) if not already installed OR if installed one is not the latest
//To Update BlueSky R pacakge there is different menu options.
if (!isinstalled || !islatestinstalled)
{
logService.WriteToLogLevel("Install BlueSky R pacakge if its not already installed or not latest:", LogLevelEnum.Info);
//string parentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location).Replace('\\', '/') + "/RPackages/BlueSky R Package(s)";
if (Directory.Exists(parentDir))
{
//find all the .zip file in RPacakges directory
//string[] RpackageFullPathFilenames = Directory.GetFiles(parentDir, "BlueSky*.zip");//only look for packages with names "BlueSky*.zip"
res = rpm.InstallMultiPackageFromZip(RpackageFullPathFilenames, true, true);
}
else
{
res.Error = "Could not find BlueSky R package(s). Please install them by going to Tools > Package > Update BlueSky package from zip (Restart App)";
}
}
return res;
}