Skip to content

Commit

Permalink
Updated how build numbers are done. Update check now always comes bef…
Browse files Browse the repository at this point in the history
…ore manifest update check, to avoid an issue where no-internet could cause it to be unable to update - or if there was some sort of error and the program needed an update but would close before one could be done. Added some more try catch on file operations.
  • Loading branch information
Mgamerz committed Jun 1, 2017
1 parent e4fa97c commit cd8ef79
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 66 deletions.
21 changes: 17 additions & 4 deletions AlotAddOnGUI/AlotAddOnGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Properties\AssemblyInfo.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AssemblyInfo.tt</DependentUpon>
</Compile>
<Compile Include="Utilites.cs" />
<Compile Include="Updater\AnonymousPipes.cs" />
<Page Include="MainWindow.xaml">
Expand All @@ -116,9 +121,6 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand All @@ -134,6 +136,10 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\AssemblyInfo.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AssemblyInfo.cs</LastGenOutput>
</None>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand All @@ -160,7 +166,6 @@
<Content Include="memodder\MassEffectModder.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="memodder\MassEffectModder.pdb" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">
Expand All @@ -174,6 +179,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand All @@ -196,8 +204,13 @@ copy /y "$(TargetDir)Updater\GHUpdater.exe" "$(TargetDir)bin\GHUpdater.exe"
copy /y "$(TargetDir)7z\7z.exe" "$(TargetDir)bin\7z.exe"
copy /y "$(TargetDir)7z\7z.dll" "$(TargetDir)bin\7z.dll"
copy /y "$(TargetDir)memodder\MassEffectModder.exe" "$(TargetDir)bin\MassEffectModder.exe"
del "$(TargetDir)lib\*.pdb"
del "$(TargetDir)lib\manifest*.xml"
rmdir /s /q "$(TargetDir)memodder"
rmdir /s /q "$(TargetDir)7z"
rmdir /s /q "$(TargetDir)Updater"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>if $(ConfigurationName) == Debug ("%25ProgramFiles%25\Microsoft Visual Studio\2017\Community\Common7\IDE\TextTransform.exe" -a !!build!true "$(ProjectDir)Properties\AssemblyInfo.tt") ELSE ("%25ProgramFiles%25\Microsoft Visual Studio\2017\Community\Common7\IDE\TextTransform.exe" -a !!revision!true -a !!build!true "$(ProjectDir)Properties\AssemblyInfo.tt")</PreBuildEvent>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions AlotAddOnGUI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Center">
<TextBlock x:Name="HeaderLabel" TextAlignment="Center" Text="Download the listed files, then drag and drop the files onto this window.&#x0a;Once all items are ready, build the addon." TextWrapping="Wrap" />
<TextBlock x:Name="HeaderLabel" TextAlignment="Center" Text="Preparing application..." TextWrapping="Wrap" />
</Label>
<Label Grid.Column="0" Grid.Row="1" x:Name="AddonFilesLabel" HorizontalContentAlignment="Center" Content="AddOn Files"/>
<ProgressBar Minimum="0" Maximum="100" x:Name="Install_ProgressBar" Grid.Column="0" Grid.Row="2"/>
<ProgressBar Minimum="0" Maximum="100" x:Name="Install_ProgressBar" Grid.Column="0" Grid.Row="2" IsIndeterminate="true"/>

<ListView Grid.Column="0" Grid.Row="3" Name="lvUsers">
<!-- This is what each list item looks like-->
Expand Down
47 changes: 29 additions & 18 deletions AlotAddOnGUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,18 @@ public MainWindow()
{
InitializeComponent();
Title = "ALOT Addon Builder " + System.Reflection.Assembly.GetEntryAssembly().GetName().Version;
InitializeComponent();
RunUpdater();
HeaderLabel.Text = "Preparing application...";
}

private async void RunUpdater()
private void RunUpdater()
{
await Task.Delay(TimeSpan.FromSeconds(4));

Log.Information("Running updater.");
Log.Information("Running GHUpdater.");
AddonFilesLabel.Content = "Checking for application updates";
string updaterpath = EXE_DIRECTORY + BINARY_DIRECTORY + "GHUpdater.exe";
string temppath = Path.GetTempPath() + "GHUpdater.exe";
File.Copy(updaterpath, temppath, true);
pipe = new AnonymousPipes("Server end of the pipe.", temppath, "additionalArgs=your_own_command_line_args_here", delegate (String msg)
pipe = new AnonymousPipes("GHUPDATE_SERVER.", temppath, "", delegate (String msg)
{
Dispatcher.Invoke((MethodInvoker)async delegate ()
{
Expand All @@ -77,6 +76,7 @@ private async void RunUpdater()
{
//updateprogresscontroller.SetTitle("Update ready to install");
//updateprogresscontroller.SetMessage("Update will install in 5 seconds.");
await this.ShowMessageAsync("ALOT Addon Builder update ready", "The program will close and update in the background, then reopen. It should only take a few seconds.");
string updatemessage = "EXECUTE_UPDATE \"" + System.AppDomain.CurrentDomain.FriendlyName + "\" \"" + EXE_DIRECTORY + "\"";
Log.Information("Executing update: " + updatemessage);
pipe.SendText(updatemessage);
Expand All @@ -97,13 +97,20 @@ private async void RunUpdater()
break;
case "UP_TO_DATE":
Log.Information("GHUpdater reporting app is up to date");
//pipe.SendText("KILL_UPDATER");
//pipe.Close();
Thread.Sleep(250);
File.Delete(temppath);
try
{
File.Delete(temppath);
}
catch (Exception e)
{
Log.Error("Error deleting TEMP GHUpdater.exe: " + e.ToString());
}
await FetchManifest();
break;
case "ERROR_CHECKING_FOR_UPDATES":
AddonFilesLabel.Content = "Error occured checking for updates";
await FetchManifest();
break;
case "UPDATE_AVAILABLE":
if (clientmessage.Length != 2)
Expand All @@ -124,6 +131,7 @@ private async void RunUpdater()
pipe.SendText("KILL_UPDATER");
pipe.Close();
Log.Information("User declined update, shutting down updater");
await FetchManifest();
}
break;
}
Expand Down Expand Up @@ -246,7 +254,7 @@ private void timer_Tick(object sender, EventArgs e)
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
SetupButtons();
await FetchManifest();
RunUpdater();
}

private async void SetupButtons()
Expand Down Expand Up @@ -318,20 +326,20 @@ private async Task FetchManifest()
try
{
await webClient.DownloadFileTaskAsync("https://rawgit.com/Mgamerz/AlotAddOnGUI/master/manifest.xml", @"manifest-new.xml");
File.Delete(@"manifest.xml");
File.Move(@"manifest-new.xml", @"manifest.xml");
File.Delete(EXE_DIRECTORY + @"manifest.xml");
File.Move(EXE_DIRECTORY + @"manifest-new.xml", EXE_DIRECTORY + @"manifest.xml");
Log.Information("Manifest fetched.");
}
catch (WebException e)
{
Log.Error("Exception occured getting manifest from server: " + e.ToString());
if (File.Exists(@"manifest.xml"))
if (File.Exists(EXE_DIRECTORY + @"manifest.xml"))
{
Log.Information("Reading existing manifest.");
}

}
if (!File.Exists(@"manifest.xml"))
if (!File.Exists(EXE_DIRECTORY + @"manifest.xml"))
{
Log.Fatal("No local manifest exists to use, exiting...");
await this.ShowMessageAsync("No Manifest Available", "An error occured downloading the manifest for addon. Information that is required to build the addon is not available. Check the program logs.");
Expand All @@ -342,7 +350,8 @@ private async Task FetchManifest()
Log.Information("Manifest read. Switching over to user control");

Install_ProgressBar.IsIndeterminate = false;
AddonFilesLabel.Content = "Addon Files";
HeaderLabel.Text = "Download the listed files, then drag and drop the files onto this window.\nOnce all items are ready, build the addon.";
AddonFilesLabel.Content = "Scanning...";
timer_Tick(null, null);
}
}
Expand Down Expand Up @@ -741,7 +750,8 @@ private bool ExtractAddons(int game)
{
Directory.Delete(MEM_STAGING_DIR, true);
Directory.Delete("Extracted_Mods", true);
} catch (IOException e)
}
catch (IOException e)
{
Log.Error("Unable to delete staging and target directories. Addon should have been built however.\n" + e.ToString());
}
Expand Down Expand Up @@ -788,9 +798,10 @@ private async void InitInstall(int game)
{
Directory.Delete(MEM_STAGING_DIR, true);
}
} catch (System.IO.IOException e)
}
catch (System.IO.IOException e)
{
Log.Error("Unable to delete staging and target directories.\n"+e.ToString());
Log.Error("Unable to delete staging and target directories.\n" + e.ToString());
await this.ShowMessageAsync("Error occured while preparing directories", "ALOT Addon Builder was unable to cleanup some directories. Make sure all file explorer windows are closed that may be open in the working directories.");
return;
}
Expand Down
52 changes: 10 additions & 42 deletions AlotAddOnGUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Reflection;
using System.Resources;


using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Resources;

// General Information

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ALOTAddonBuilder")]
[assembly: AssemblyDescription("Builds the ALOT Addon File for ME2/ME3")]
[assembly: AssemblyConfiguration("")]
Expand All @@ -16,40 +16,8 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

// Version informationr(
[assembly: AssemblyVersion("1.2.3.18")]
[assembly: AssemblyFileVersion("1.2.3.18")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.*")]
//[assembly: AssemblyFileVersion("1.0.*")]
48 changes: 48 additions & 0 deletions AlotAddOnGUI/Properties/AssemblyInfo.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>

<#
bool incRevision = false;
bool incBuild = false;

try { incRevision = Convert.ToBoolean(this.Host.ResolveParameterValue("","","revision")); } catch( Exception ) { }
try { incBuild = Convert.ToBoolean(this.Host.ResolveParameterValue("","","build")); } catch( Exception ) { }
try {
string currentDirectory = Path.GetDirectoryName(Host.TemplateFile);
string assemblyInfo = File.ReadAllText(Path.Combine(currentDirectory,"AssemblyInfo.cs"));
Regex pattern = new Regex("AssemblyVersion\\(\"\\d+\\.\\d+\\.(?<revision>\\d+)\\.(?<build>\\d+)\"\\)");
MatchCollection matches = pattern.Matches(assemblyInfo);
revision = Convert.ToInt32(matches[0].Groups["revision"].Value) + (incRevision?1:0);
build = Convert.ToInt32(matches[0].Groups["build"].Value) + (incBuild?1:0);
}
catch( Exception ) { }
#>

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;

// General Information

[assembly: AssemblyTitle("ALOTAddonBuilder")]
[assembly: AssemblyDescription("Builds the ALOT Addon File for ME2/ME3")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ME3Tweaks")]
[assembly: AssemblyProduct("ALOTAddonBuilder")]
[assembly: AssemblyCopyright("Copyright © 2017 ME3Tweaks")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version informationr(
[assembly: AssemblyVersion("1.2.<#= this.revision #>.<#= this.build #>")]
[assembly: AssemblyFileVersion("1.2.<#= this.revision #>.<#= this.build #>")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

<#+
int revision = 0;
int build = 0;
#>

0 comments on commit cd8ef79

Please sign in to comment.