X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=na-get-lib%2FNaGet.Packages.Install%2FInstallation.cs;h=de5d2a1610fbf13ae98c3eee156e0cce54fdb4ca;hb=7e429ad7b8cbb759d75e3d6fce01ee9598387679;hp=8ff6026c7ecc226cc5a6e78e1b95c4fd0656def4;hpb=eaa937a13f4e1238a992a3ad79b84a7288954603;p=applistation%2FAppliStation.git
diff --git a/na-get-lib/NaGet.Packages.Install/Installation.cs b/na-get-lib/NaGet.Packages.Install/Installation.cs
index 8ff6026..de5d2a1 100644
--- a/na-get-lib/NaGet.Packages.Install/Installation.cs
+++ b/na-get-lib/NaGet.Packages.Install/Installation.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Diagnostics;
using NaGet.Net;
using NaGet.SubCommands;
+using System.Xml.Serialization;
namespace NaGet.Packages.Install
{
@@ -12,15 +13,25 @@ namespace NaGet.Packages.Install
///
public class Installation
{
+ private Package installedPackage;
+
///
/// ã¤ã³ã¹ãã¼ã«ããããã±ã¼ã¸
///
- public Package InstalledPackage;
+ public Package InstalledPackage {
+ get { return installedPackage; }
+ set {
+ installedPackage = value;
+
+ installerFile = getArchiveFilePath();
+ installerIndex = GetPreferInstallerIndex(value);
+ }
+ }
///
/// (ä¿åããã)ã¤ã³ã¹ãã¼ã©ã®ãã¡ã¤ã«ã®ãã¹
///
- public string InstallerFile;
+ private string installerFile;
///
/// ã¤ã³ã¹ãã¼ã«ãå®äºããããå¦ãã®ãã©ã°
@@ -50,27 +61,30 @@ namespace NaGet.Packages.Install
///
/// ã³ã³ã¹ãã©ã¯ã¿
///
- /// ã¤ã³ã¹ãã¼ã«ããããã±ã¼ã¸
- public Installation(Package package)
+ public Installation()
{
- InstalledPackage = package;
- InstallerFile = getArchiveFilePath();
- installerIndex = GetPreferInstallerIndex(package);
}
///
/// ã³ã³ã¹ãã©ã¯ã¿
///
/// ã¤ã³ã¹ãã¼ã«ããããã±ã¼ã¸
- /// (ä¿åããã)ã¤ã³ã¹ãã¼ã©ã®ãã¡ã¤ã«ã®ãã¹
- protected Installation(Package package, string installerfile)
+ public Installation(Package package)
{
InstalledPackage = package;
- InstallerFile = installerfile;
- installerIndex = GetPreferInstallerIndex(package);
}
///
+ /// ã¤ã³ã¹ãã¼ã©ãã¡ã¤ã«ãåå¾ãã
+ ///
+ public string InstallerFile {
+ get { return installerFile; }
+ }
+
+
+ #region ã¤ã³ã¹ãã¼ã©ç¶æ
ãã§ãã¯é¢é£
+
+ ///
/// ã¤ã³ã¹ãã¼ã«å¯è½ãå¦ã
///
public bool IsInstallablePackage()
@@ -83,7 +97,7 @@ namespace NaGet.Packages.Install
///
public bool Downloaded {
get {
- return File.Exists(InstallerFile) && ((File.GetAttributes(InstallerFile) & FileAttributes.Hidden) != FileAttributes.Hidden);
+ return File.Exists(installerFile) && ((File.GetAttributes(installerFile) & FileAttributes.Hidden) != FileAttributes.Hidden);
}
}
@@ -100,7 +114,10 @@ namespace NaGet.Packages.Install
public bool InstallSuccessed {
get {
switch (InstalledPackage.Type) {
- case InstallerType.ARCHIVE: // ã¢ã¼ã«ã¤ãã¤ã³ã¹ãã¼ã©ã¯ãã©ã«ãã®ç¢ºèª
+ case InstallerType.ARCHIVE:
+ case InstallerType.ITSELF:
+ // ã¢ã¼ã«ã¤ãã¤ã³ã¹ãã¼ã©ããã³é
å¸exeããèªèº«ãå®è¡ãã¡ã¤ã«ã®ã¨ãã
+ // ï¼AppliStationã®ä½ãï¼ããã°ã©ã ãã©ã«ãã®åå¨ã®ã¿ã§ç¢ºèªãè¡ãã
return Directory.Exists(Path.Combine(NaGet.Env.ArchiveProgramFiles, InstalledPackage.Name));
case InstallerType.EXEC_INSTALLER:
case InstallerType.MSI_PACKAGE:
@@ -116,7 +133,7 @@ namespace NaGet.Packages.Install
///
public bool Silent {
get {
- return (IsSupportsSilentOnly)? true :
+ return (SupportsSilentOnly)? true :
(IsSupportsSilent)? silent :
false;
}
@@ -130,8 +147,11 @@ namespace NaGet.Packages.Install
get {
switch (InstalledPackage.Type) {
case InstallerType.ARCHIVE:
+ case InstallerType.ITSELF:
case InstallerType.MSI_PACKAGE:
return true;
+ case InstallerType.EXEC_INSTALLER:
+ return ! string.IsNullOrEmpty(InstalledPackage.SilentInstallArguments);
default:
return false;
}
@@ -141,11 +161,27 @@ namespace NaGet.Packages.Install
///
/// ãµã¤ã¬ã³ãã¤ã³ã¹ãã¼ã«ã ãããµãã¼ããã¦ãããå¦ã
///
- public bool IsSupportsSilentOnly {
- get { return InstalledPackage.Type == InstallerType.ARCHIVE; }
+ public bool SupportsSilentOnly {
+ get {
+ return (InstalledPackage.Type == InstallerType.ARCHIVE)
+ || (InstalledPackage.Type == InstallerType.ITSELF);
+ }
}
///
+ /// é¸æãããããã±ã¼ã¸ã¯ãAppliStationã§ã¯ãªãPCã¸ã®ã¤ã³ã¹ãã¼ã«ãããã®ãå¦ããè¿ãã
+ ///
+ /// RunAsãå¿
è¦ãå¦ãã®å¤æã«ãããããã
+ public bool TargetPC {
+ get {
+ return (InstalledPackage.Type != InstallerType.ARCHIVE)
+ && (InstalledPackage.Type != InstallerType.ITSELF);
+ }
+ }
+
+ #endregion
+
+ ///
/// ãã¦ã³ãã¼ããè¡ãã
///
/// ãã¦ã³ãã¼ããªãã¸ã§ã¯ã
@@ -153,14 +189,45 @@ namespace NaGet.Packages.Install
{
if (! Installed) {
string url = InstalledPackage.Installer[installerIndex].Url.Href;
- downloader.Download(url, InstallerFile);
+ downloader.Download(url, installerFile);
// ãµã¼ãæå®ã®ãã¡ã¤ã«åã«å¤æ´ãã
if (! string.IsNullOrEmpty(downloader.DownloadedFileName)) {
- string newFile = Path.Combine(Path.GetDirectoryName(InstallerFile), downloader.DownloadedFileName);
- File.Move(InstallerFile, newFile);
- InstallerFile = newFile;
+ string newFile = Path.Combine(Path.GetDirectoryName(installerFile), downloader.DownloadedFileName);
+ File.Move(installerFile, newFile);
+ installerFile = newFile;
}
+
+ // 権éã親ãã©ã«ãã«è½ã¨ã
+ try {
+ string targetDir = Path.GetDirectoryName(installerFile);
+ NaGet.Utils.SetAccessControlRecursive(targetDir, File.GetAccessControl(Path.GetDirectoryName(targetDir)));
+ } catch (Exception) {} // 失ææã¯ä½ãããªã
+ }
+ }
+
+ ///
+ /// ã¤ã³ã¹ãã¼ã©ãã¡ã¤ã«ãã¹ãã£ã³ãã
+ ///
+ /// ã¦ã¤ã«ã¹ã®ããéé¿ã»åé¤ãããã¨ããä¾å¤ãæããã«ããããæ£å¸¸ãã®ããã«åä½ããã¾ãã
+ /// ã¹ãã£ã³ã§æå³ãã¬åä½ããã£ãã¨ã
+ /// ã¹ãã£ã³å¾ã«ã¤ã³ã¹ãã¼ã©ãã¡ã¤ã«ãåå¨ããªãã¨ã
+ /// ã¹ãã£ãã¼ãªãã¸ã§ã¯ã
+ public void ScanInstallerFile(DownloadScanner scanner)
+ {
+ Exception e = null;
+ try {
+ scanner.Scan(installerFile, InstalledPackage.Installer[installerIndex].Url.Href);
+ } catch (System.Runtime.InteropServices.COMException ex) {
+ e = ex;
+ }
+
+ if (! File.Exists(installerFile)) {
+ // ãã¡ã¤ã«ãæ¶ããã¦ãããªãã°FileNotFoundExceptionãåºã
+ throw new FileNotFoundException(string.Empty, installerFile, e);
+ } else if ( e != null ) {
+ // ãã¡ã¤ã«ãæ¶ããã¦ããªããä¾å¤ãçºçãã¦ããã¨ãã¯ããã®ä¾å¤ãæãã
+ throw e;
}
}
@@ -183,7 +250,7 @@ namespace NaGet.Packages.Install
HashValue[] hashValues = InstalledPackage.Installer[installerIndex].Hash;
if (hashValues != null) {
foreach (HashValue hash in hashValues) {
- if (! hash.Validate(InstallerFile)) {
+ if (! hash.Validate(installerFile)) {
return false;
}
}
@@ -202,25 +269,38 @@ namespace NaGet.Packages.Install
try {
switch (type) {
case InstallerType.EXEC_INSTALLER:
- hProcess = Process.Start(installerfile);
+ if (Silent) {
+ hProcess = Process.Start(installerfile, InstalledPackage.SilentInstallArguments);
+ } else {
+ hProcess = Process.Start(installerfile);
+ }
break;
case InstallerType.MSI_PACKAGE:
- string msiexecArgs = string.Format("{0} /i \"{1}\"",
+ string msiexecArgs = string.Format("{0} /norestart /i \"{1}\" REBOOT=ReallySuppress",
(Silent)? "/passive" : string.Empty,
installerfile);
hProcess = Process.Start("msiexec", msiexecArgs);
break;
case InstallerType.ARCHIVE:
+ case InstallerType.ITSELF:
string argument = string.Format("-i \"{0}\" \"{1}\"", installerfile, this.InstalledPackage.Name);
hProcess = createExtractArchiveProcess(argument,
this.OutputDataReceived,
this.ErrorDataReceived);
+ // Note: ARCHIVEãITSELFã®å¤æã¯archive-instãè¡ã
break;
default:
throw new NotImplementedException("Not implemented archive installation yet");
}
+
+ if (NaGet.Env.InstallProcessOnBackground) {
+ try {
+ hProcess.PriorityClass = ProcessPriorityClass.Idle;
+ } catch (Exception) {}
+ }
+
hProcess.WaitForExit();
return hProcess.ExitCode;
@@ -237,7 +317,7 @@ namespace NaGet.Packages.Install
/// ã¤ã³ã¹ãã¼ã©ã®çµäºã³ã¼ã
public int Install()
{
- string installerFile = this.InstallerFile;
+ string installerFile = this.installerFile;
string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
// ã¢ã¼ã«ã¤ãããã¦ãããªãä¸æ¦å±é
@@ -248,6 +328,12 @@ namespace NaGet.Packages.Install
using (Process hProcess = createExtractArchiveProcess(argument,
this.OutputDataReceived,
this.ErrorDataReceived)) {
+ if (NaGet.Env.InstallProcessOnBackground) {
+ try {
+ hProcess.PriorityClass = ProcessPriorityClass.Idle;
+ } catch (Exception) {}
+ }
+
hProcess.WaitForExit();
if (hProcess.ExitCode != 0) {
@@ -261,7 +347,6 @@ namespace NaGet.Packages.Install
}
}
-
int exitCode = invokeInstaller(installerFile, InstalledPackage.Type);
installed = true;
@@ -302,7 +387,7 @@ namespace NaGet.Packages.Install
}
///
- /// ã¤ã³ã¹ãã¼ã©ã®ä¸æä¿åå
ãã¹ãçæ
+ /// ã¤ã³ã¹ãã¼ã©ã®ä¿åå
ãã¹ãçæ
///
private string getArchiveFilePath()
{
@@ -320,6 +405,11 @@ namespace NaGet.Packages.Install
}
} else {
Directory.CreateDirectory(folder);
+
+ // 権éã親ãã©ã«ãã«åããã
+ try {
+ Directory.SetAccessControl(folder, Directory.GetAccessControl(Path.GetDirectoryName(folder)));
+ } catch (Exception) {} // 失ææç¡è¦
}
}
@@ -367,6 +457,9 @@ namespace NaGet.Packages.Install
list.AddRange(Directory.GetFiles(basedir, "*.7z"));
list.AddRange(Directory.GetFiles(basedir, "*.tar*"));
break;
+ case InstallerType.ITSELF:
+ list.AddRange(Directory.GetFiles(basedir, "*.exe"));
+ break;
default:
return null;
}
@@ -408,6 +501,8 @@ namespace NaGet.Packages.Install
new FileNotFoundException(errMsg, archiveInstExe));
}
+
+
ProcessStartInfo procInfo = new ProcessStartInfo(archiveInstExe, archiveInstArgs);
procInfo.UseShellExecute = false;
procInfo.CreateNoWindow = true;
@@ -421,8 +516,8 @@ namespace NaGet.Packages.Install
///
public virtual void RemoveDownloadedFile()
{
- if (Downloaded && File.Exists(InstallerFile)) {
- File.Delete(InstallerFile);
+ if (Downloaded && File.Exists(installerFile)) {
+ File.Delete(installerFile);
}
}