2019-07-28 23:53:15 +03:00
|
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
2017-06-05 17:09:24 +03:00
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
2023-11-29 12:35:53 +03:00
|
|
|
|
using System.Linq;
|
2017-06-05 17:09:24 +03:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace VisualPascalABC
|
|
|
|
|
|
{
|
2023-04-19 19:53:42 +03:00
|
|
|
|
delegate void NugetPackageInstallHandler(bool result, string[] dlls, string[] xmls, string[] ndlls);
|
2017-06-05 17:09:24 +03:00
|
|
|
|
delegate void NugetPackageOutputHandler(string output);
|
|
|
|
|
|
|
|
|
|
|
|
class NuGetTasks
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void InstallPackage(string packageId, string workingDir, NugetPackageInstallHandler finishAction, NugetPackageOutputHandler outputAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dir = Path.Combine(workingDir, "nuget");
|
|
|
|
|
|
dir = Path.Combine(dir, packageId);
|
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
|
Process nugetProcess = new Process();
|
|
|
|
|
|
nugetProcess.StartInfo.FileName = Path.Combine(PascalABCCompiler.Tools.GetExecutablePath(), "nuget.exe");
|
|
|
|
|
|
nugetProcess.StartInfo.UseShellExecute = false;
|
|
|
|
|
|
nugetProcess.StartInfo.Arguments = "install "+packageId+ " -NonInteractive";
|
2023-04-19 19:53:42 +03:00
|
|
|
|
nugetProcess.StartInfo.CreateNoWindow = false;
|
|
|
|
|
|
nugetProcess.StartInfo.RedirectStandardOutput = false;
|
|
|
|
|
|
nugetProcess.StartInfo.RedirectStandardError = false;
|
2017-06-05 17:09:24 +03:00
|
|
|
|
nugetProcess.StartInfo.WorkingDirectory = dir;
|
|
|
|
|
|
nugetProcess.EnableRaisingEvents = true;
|
2023-04-19 19:53:42 +03:00
|
|
|
|
//nugetProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
|
2017-06-05 17:09:24 +03:00
|
|
|
|
nugetProcess.Exited += new EventHandler(delegate (object o, EventArgs a) {
|
|
|
|
|
|
string[] dlls;
|
|
|
|
|
|
string[] xmls;
|
2023-04-19 19:53:42 +03:00
|
|
|
|
string[] ndlls;
|
|
|
|
|
|
bool result = getPackage(dir, out dlls, out xmls, out ndlls);
|
|
|
|
|
|
finishAction(result, dlls, xmls, ndlls);
|
2017-06-05 17:09:24 +03:00
|
|
|
|
});
|
|
|
|
|
|
nugetProcess.Start();
|
|
|
|
|
|
nugetProcess.WaitForExit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-29 12:35:53 +03:00
|
|
|
|
static string getDotnetDir(string startDir)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 481 48 472 471 47 462 461 46 452 451 45 4
|
|
|
|
|
|
var s = "481 48 472 471 47 462 461 46 452 451 45 4";
|
|
|
|
|
|
var ss = s.Split().Reverse().Select(d => "net" + d).ToList();
|
|
|
|
|
|
ss.Add("netstandard2.0");
|
|
|
|
|
|
ss.Add("net");
|
|
|
|
|
|
|
|
|
|
|
|
string Dir = "";
|
|
|
|
|
|
foreach (var dd in ss)
|
|
|
|
|
|
{
|
|
|
|
|
|
Dir = Path.Combine(startDir, dd);
|
|
|
|
|
|
if (Directory.Exists(Dir))
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*string Dir = Path.Combine(startDir, "net40");
|
|
|
|
|
|
if (!Directory.Exists(Dir))
|
|
|
|
|
|
Dir = Path.Combine(startDir, "net45");
|
|
|
|
|
|
if (!Directory.Exists(Dir))
|
|
|
|
|
|
Dir = Path.Combine(startDir, "net46");
|
|
|
|
|
|
if (!Directory.Exists(Dir))
|
|
|
|
|
|
Dir = Path.Combine(startDir, "netstandard2.0");
|
|
|
|
|
|
if (!Directory.Exists(Dir))
|
|
|
|
|
|
Dir = Path.Combine(startDir, "net");*/
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(Dir))
|
|
|
|
|
|
Dir = startDir;
|
|
|
|
|
|
return Dir;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-19 19:53:42 +03:00
|
|
|
|
static bool getPackage(string workingDir, out string[] dlls, out string[] xmls, out string[] ndlls)
|
2017-06-05 17:09:24 +03:00
|
|
|
|
{
|
|
|
|
|
|
dlls = null;
|
|
|
|
|
|
xmls = null;
|
2023-04-19 19:53:42 +03:00
|
|
|
|
ndlls = null;
|
2017-06-05 17:09:24 +03:00
|
|
|
|
List<string> dllList = new List<string>();
|
|
|
|
|
|
List<string> xmlList = new List<string>();
|
2023-04-19 19:53:42 +03:00
|
|
|
|
List<string> nativedllList = new List<string>();
|
2017-06-05 17:09:24 +03:00
|
|
|
|
bool result = false;
|
|
|
|
|
|
foreach (string dir in Directory.EnumerateDirectories(workingDir))
|
|
|
|
|
|
{
|
|
|
|
|
|
string libDir = Path.Combine(dir, "lib");
|
|
|
|
|
|
if (Directory.Exists(libDir))
|
|
|
|
|
|
{
|
2023-11-29 12:35:53 +03:00
|
|
|
|
string dotnetDir = getDotnetDir(libDir);
|
|
|
|
|
|
|
|
|
|
|
|
/*string dotnetDir = Path.Combine(libDir, "net40");
|
2017-06-05 17:09:24 +03:00
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(libDir, "net45");
|
|
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(libDir, "net46");
|
2023-04-19 19:53:42 +03:00
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(libDir, "netstandard2.0");
|
2017-06-05 17:09:24 +03:00
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(libDir, "net");
|
|
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
2023-11-29 12:35:53 +03:00
|
|
|
|
dotnetDir = libDir;*/
|
|
|
|
|
|
|
2017-06-05 17:09:24 +03:00
|
|
|
|
if (Directory.Exists(dotnetDir))
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] dllFiles = Directory.GetFiles(dotnetDir, "*.dll");
|
|
|
|
|
|
if (dllFiles.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
dllList.AddRange(dllFiles);
|
|
|
|
|
|
dlls = dllFiles;
|
|
|
|
|
|
string[] xmlFiles = Directory.GetFiles(dotnetDir, "*.xml");
|
|
|
|
|
|
if (xmlFiles.Length > 0)
|
|
|
|
|
|
xmlList.AddRange(xmlFiles);
|
|
|
|
|
|
result = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-04-19 19:53:42 +03:00
|
|
|
|
// А теперь разбираемся с native dlls. Они находятся в папке runtimes\win-x64\nativeassets\такое же окончание как в dotnetdir
|
|
|
|
|
|
string runtimesDir = Path.Combine(dir, "runtimes", "win-x64", "nativeassets");
|
|
|
|
|
|
if (!Directory.Exists(runtimesDir))
|
|
|
|
|
|
runtimesDir = Path.Combine(dir, "runtimes", "win-x64", "native");
|
|
|
|
|
|
if (Directory.Exists(runtimesDir))
|
|
|
|
|
|
{
|
2023-11-29 12:35:53 +03:00
|
|
|
|
/*string dotnetDir = Path.Combine(runtimesDir, "net40");
|
2023-04-19 19:53:42 +03:00
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(runtimesDir, "net45");
|
|
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(runtimesDir, "net46");
|
|
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(runtimesDir, "netstandard2.0");
|
|
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = Path.Combine(runtimesDir, "net");
|
|
|
|
|
|
if (!Directory.Exists(dotnetDir))
|
|
|
|
|
|
dotnetDir = runtimesDir;
|
2023-11-29 12:35:53 +03:00
|
|
|
|
*/
|
|
|
|
|
|
string dotnetDir = getDotnetDir(runtimesDir);
|
|
|
|
|
|
|
2023-04-19 19:53:42 +03:00
|
|
|
|
if (Directory.Exists(dotnetDir))
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] nativedllFiles = Directory.GetFiles(dotnetDir, "*.dll");
|
|
|
|
|
|
if (nativedllFiles.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
nativedllList.AddRange(nativedllFiles);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-05 17:09:24 +03:00
|
|
|
|
}
|
|
|
|
|
|
dlls = dllList.ToArray();
|
|
|
|
|
|
xmls = xmlList.ToArray();
|
2023-04-19 19:53:42 +03:00
|
|
|
|
ndlls = nativedllList.ToArray();
|
2017-06-05 17:09:24 +03:00
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|