Skip to content

Commit

Permalink
Now cold updates correctly load custom Task objects
Browse files Browse the repository at this point in the history
  • Loading branch information
synhershko committed Jul 26, 2012
1 parent 2b45994 commit b7b626b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/NAppUpdate.Framework/Utils/FileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Collections.Generic;
using System.IO;

namespace NAppUpdate.Framework.Utils
{
Expand Down Expand Up @@ -52,5 +53,14 @@ public static void DeleteDirectory(string targetDir)
File.SetAttributes(targetDir, FileAttributes.Normal);
Directory.Delete(targetDir, false);
}

public static IEnumerable<string> GetFiles(string path, string searchPattern, SearchOption searchOption)
{
string[] searchPatterns = searchPattern.Split('|');
var files = new List<string>();
foreach (string sp in searchPatterns)
files.AddRange(System.IO.Directory.GetFiles(path, sp, searchOption));
return files;
}
}
}
28 changes: 26 additions & 2 deletions src/NAppUpdate.Updater/AppStart.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using System.Threading;
using NAppUpdate.Framework;
Expand Down Expand Up @@ -33,11 +34,11 @@ private static void Main()

Log("Starting to process cold updates...");

var workingDir = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
if (_args.Log)
{
// Setup a temporary location for the log file, until we can get the DTO
logFile = System.Reflection.Assembly.GetEntryAssembly().Location;
logFile = Path.Combine(Path.GetDirectoryName(logFile), @"NauUpdate.log");
logFile = Path.Combine(workingDir, @"NauUpdate.log");
}

try
Expand All @@ -51,6 +52,29 @@ private static void Main()

Log("Update process name: '{0}'", syncProcessName);

// Load extra assemblies to the app domain, if present
var availableAssemblies = FileSystem.GetFiles(workingDir, "*.exe|*.dll", SearchOption.TopDirectoryOnly);
foreach (var assemblyPath in availableAssemblies)
{
Log("Loading {0}", assemblyPath);

if (assemblyPath.Equals(System.Reflection.Assembly.GetEntryAssembly().Location, StringComparison.InvariantCultureIgnoreCase)
|| assemblyPath.EndsWith("NAppUpdate.Framework.dll"))
{
Log("\tSkipping (part of current execution)");
continue;
}

try
{
var assembly = System.Reflection.Assembly.LoadFile(assemblyPath);
}
catch (System.BadImageFormatException ex)
{
Log("\tSkipping due to an error: {0}", ex.Message);
}
}

// Connect to the named pipe and retrieve the updates list
var dto = NauIpc.ReadDto(syncProcessName) as NauIpc.NauDto;

Expand Down
10 changes: 6 additions & 4 deletions src/NAppUpdate.Updater/ArgumentsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ public void Parse(string[] args)
// Skip any args that are our own executable (first arg should be this).
// In Visual Studio, the arg will be the VS host starter instead of
// actually ourself.
if (arg.ToLower() == System.Reflection.Assembly.GetEntryAssembly().Location.ToLower()
|| arg.ToLower().Contains(".vshost.exe"))
continue;
if (arg.Equals(System.Reflection.Assembly.GetEntryAssembly().Location, StringComparison.InvariantCultureIgnoreCase)
|| arg.EndsWith(".vshost.exe", StringComparison.InvariantCultureIgnoreCase))
{
continue;
}

arg = CleanArg(arg);
arg = CleanArg(arg);
if (arg == "log") {
this.Log = true;
this.HasArgs = true;
Expand Down

0 comments on commit b7b626b

Please sign in to comment.