Skip to content

Commit 1438f66

Browse files
jasonjason
authored andcommitted
automated update process if selected build 009
1 parent baa52d6 commit 1438f66

File tree

4 files changed

+79
-58
lines changed

4 files changed

+79
-58
lines changed

TextFilter/App.config

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,4 @@
2626
<add key="WordWrap" value="True" />
2727
<add key="ClientSettingsProvider.ServiceUri" value="" />
2828
</appSettings>
29-
<system.web>
30-
<membership defaultProvider="ClientAuthenticationMembershipProvider">
31-
<providers>
32-
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
33-
</providers>
34-
</membership>
35-
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
36-
<providers>
37-
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
38-
</providers>
39-
</roleManager>
40-
</system.web>
4129
</configuration>

TextFilter/Base/MainViewModel.cs

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Collections.ObjectModel;
1414
using System.Diagnostics;
1515
using System.IO;
16+
using System.IO.Compression;
1617
using System.Linq;
1718
using System.Reflection;
1819
using System.Text;
@@ -374,26 +375,7 @@ public void SettingsExecuted(object sender)
374375
{
375376
case OptionsDialog.OptionsDialogResult.apply:
376377
{
377-
StringBuilder args = new StringBuilder();
378-
if (Settings.CurrentFilterFiles.Count > 0)
379-
{
380-
args.Append(string.Format("/filter: \"{0}\"", string.Join("\";\"", Settings.CurrentFilterFiles)));
381-
}
382-
383-
if (Settings.CurrentLogFiles.Count > 0)
384-
{
385-
if (args.Length > 0)
386-
{
387-
args.Append(" ");
388-
}
389-
390-
args.Append(string.Format("/log: \"{0}\"", string.Join("\";\"", Settings.CurrentLogFiles)));
391-
}
392-
393-
Settings.Save();
394-
CreateProcess(Process.GetCurrentProcess().MainModule.FileName, args.ToString());
395-
Debug.Print(args.ToString());
396-
Application.Current.Shutdown();
378+
Restart();
397379
break;
398380
}
399381
//case OptionsDialog.OptionsDialogResult.cancel:
@@ -431,6 +413,30 @@ public void SettingsExecuted(object sender)
431413
}
432414
}
433415

416+
private void Restart()
417+
{
418+
StringBuilder args = new StringBuilder();
419+
if (Settings.CurrentFilterFiles.Count > 0)
420+
{
421+
args.Append(string.Format("/filter: \"{0}\"", string.Join("\";\"", Settings.CurrentFilterFiles)));
422+
}
423+
424+
if (Settings.CurrentLogFiles.Count > 0)
425+
{
426+
if (args.Length > 0)
427+
{
428+
args.Append(" ");
429+
}
430+
431+
args.Append(string.Format("/log: \"{0}\"", string.Join("\";\"", Settings.CurrentLogFiles)));
432+
}
433+
434+
Settings.Save();
435+
CreateProcess(Process.GetCurrentProcess().MainModule.FileName, args.ToString());
436+
Debug.Print(args.ToString());
437+
Application.Current.Shutdown();
438+
}
439+
434440
public void VersionCheckExecuted(object sender)
435441
{
436442
VersionCheck(false);
@@ -484,26 +490,29 @@ private void HandleNewCurrentStatus(object sender, string status)
484490

485491
private void VersionCheck(bool silent)
486492
{
493+
string destFile = string.Empty;
494+
string downloadLocation = string.Empty;
495+
string message = string.Empty;
496+
string version = string.Empty;
497+
487498
try
488499
{
489500
if (string.IsNullOrEmpty(Settings.VersionCheckFile))
490501
{
502+
message = "version check url not specified";
503+
491504
if (silent)
492505
{
493-
SetStatus("VersionCheckExecuted:version check url not specified");
506+
SetStatus(message);
494507
}
495508
else
496509
{
497-
MessageBox.Show("version check url not specified");
510+
MessageBox.Show(message);
498511
}
499-
500512
return;
501513
}
502-
503-
string version = string.Empty;
514+
504515
string workingVersion = Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion;
505-
string downloadLocation = string.Empty;
506-
string destFile = string.Empty;
507516
string workingDir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
508517

509518
XmlDocument doc = new XmlDocument();
@@ -518,15 +527,7 @@ private void VersionCheck(bool silent)
518527
}
519528
if (string.IsNullOrEmpty(downloadLocation))
520529
{
521-
string message = "unable to check version: " + Settings.VersionCheckFile;
522-
if (silent)
523-
{
524-
SetStatus("VersionCheck:" + message);
525-
}
526-
else
527-
{
528-
MessageBox.Show(message);
529-
}
530+
message = "unable to check version: " + Settings.VersionCheckFile;
530531
}
531532
else if (string.Compare(version, workingVersion, true) > 0)
532533
{
@@ -545,19 +546,49 @@ private void VersionCheck(bool silent)
545546
{
546547
string downloadZip = string.Format("{0}\\{1}", workingDir.TrimEnd('\\'), Path.GetFileName(downloadLocation));
547548
(new System.Net.WebClient()).DownloadFile(downloadLocation, downloadZip);
548-
MessageBox.Show(string.Format("New version has been downloaded from: {0} \n to: {1}.\nExtract zip and restart.", downloadLocation, downloadZip));
549-
CreateProcess("explorer.exe", workingDir);
549+
550+
string downloadZipDir = string.Format("{0}-{1}",Path.GetFileNameWithoutExtension(downloadZip),version);
551+
552+
if (Directory.Exists(downloadZipDir))
553+
{
554+
Directory.Delete(downloadZipDir);
555+
}
556+
557+
// extract zip
558+
ZipFile.ExtractToDirectory(downloadZip, downloadZipDir);
559+
File.Delete(downloadZip);
560+
561+
string currentExe = Process.GetCurrentProcess().MainModule.FileName;
562+
//string currentConfig = currentExe + ".config";
563+
string currentProcessName = Process.GetCurrentProcess().MainModule.ModuleName;
564+
string newExe = string.Format("{0}\\{1}", downloadZipDir, currentProcessName);
565+
//string newConfig = newExe + ".config";
566+
567+
// overwrite exe
568+
File.Move(currentExe, currentExe + ".old");
569+
File.Copy(newExe, currentExe, true);
570+
571+
// todo: merge configs?
572+
Restart();
550573
}
551574
}
552575
}
576+
else if (string.Compare(version, workingVersion, true) < 0)
577+
{
578+
message = string.Format("running version is newer. running ver: {0} update ver: {1}", workingVersion, version);
579+
}
553580
else
554581
{
555-
string message = "version is same: " + workingVersion;
556-
if (silent)
557-
{
558-
SetStatus("VersionCheck:" + message);
559-
}
560-
else
582+
message = "version is same: " + workingVersion;
583+
}
584+
585+
if (silent)
586+
{
587+
SetStatus("VersionCheck:" + message);
588+
}
589+
else
590+
{
591+
if (!string.IsNullOrEmpty(message))
561592
{
562593
MessageBox.Show(message);
563594
}

TextFilter/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
//
4242
// You can specify all the values or you can default the Build and Revision Numbers by using the '*'
4343
// as shown below: [assembly: AssemblyVersion("1.0.*")]
44-
[assembly: AssemblyVersion("0.7.0.008")]
45-
[assembly: AssemblyFileVersion("0.7.0.008")]
44+
[assembly: AssemblyVersion("0.7.0.009")]
45+
[assembly: AssemblyFileVersion("0.7.0.009")]
4646
[assembly: GuidAttribute("9BD5B347-AF37-414D-AE8B-2D6FA05B051D")]

TextFilter/TextFilter.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
<Reference Include="System.Configuration" />
119119
<Reference Include="System.Data" />
120120
<Reference Include="System.Drawing" />
121+
<Reference Include="System.IO.Compression" />
122+
<Reference Include="System.IO.Compression.FileSystem" />
121123
<Reference Include="System.Web" />
122124
<Reference Include="System.Web.Extensions" />
123125
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

0 commit comments

Comments
 (0)