Skip to content

Commit

Permalink
Generate update config after build for classic
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Sep 17, 2017
1 parent 243e369 commit eae7371
Show file tree
Hide file tree
Showing 11 changed files with 269 additions and 113 deletions.
21 changes: 17 additions & 4 deletions Permadelete.FrontEnd/Permadelete.FrontEnd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,29 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>copy $(ProjectDir)\Helpers\Keys.cs $(SolutionDir)\Publish\Keys-empty.cs /y
<PreBuildEvent>echo "Swapping Key file..."
copy $(ProjectDir)\Helpers\Keys.cs $(SolutionDir)\Publish\Keys-empty.cs /y
copy $(SolutionDir)\Publish\Keys.cs $(ProjectDir)\Helpers\Keys.cs /y</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>copy $(SolutionDir)\Publish\Keys-empty.cs $(ProjectDir)\Helpers\Keys.cs /y
<PostBuildEvent>echo "Cleaning up..."
copy $(SolutionDir)\Publish\Keys-empty.cs $(ProjectDir)\Helpers\Keys.cs /y
del /Q /F $(TargetDir)\SharpRaven.pdb

if "$(ConfigurationName)" == "WindowsStore" (
MakeAppx pack -d $(TargetDir) -p $(ProjectDir)\bin\WindowsStorePackage\Permadelete.appx -l
signtool.exe sign -f $(ProjectDir)\bin\WindowsStorePackage\test.pfx -p 123456 -fd SHA256 -v $(ProjectDir)\bin\WindowsStorePackage\Permadelete.appx
echo "Making Appx package..."
echo "Runnning: MakeAppx pack /o /d $(TargetDir) /p $(ProjectDir)\bin\WindowsStorePackage\Permadelete.appx /l"
MakeAppx pack /o /d $(TargetDir) /p $(ProjectDir)\bin\WindowsStorePackage\Permadelete.appx /l

echo "Signing package..."
echo "Runnning: signtool.exe sign /f $(ProjectDir)\bin\WindowsStorePackage\test.pfx /p 123456 /fd SHA256 /v $(ProjectDir)\bin\WindowsStorePackage\Permadelete.appx"
signtool.exe sign /f $(ProjectDir)\bin\WindowsStorePackage\test.pfx /p 123456 /fd SHA256 /v $(ProjectDir)\bin\WindowsStorePackage\Permadelete.appx
)

if "$(ConfigurationName)" == "Classic" (
echo "Getting version number..."
echo "Running: $(SolutionDir)Publish\ufactory\ufactory.exe -source $(TargetDir) -output $(SolutionDir)Publish\Update -target $(TargetName)$(TargetExt)"
$(SolutionDir)Publish\ufactory\ufactory.exe -source $(TargetDir) -output $(SolutionDir)Publish\Update -target $(TargetName)$(TargetExt)
)</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
12 changes: 10 additions & 2 deletions Permadelete.UpdateFactory/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion Permadelete.UpdateFactory/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Permadelete.UpdateFactory"
StartupUri="MainWindow.xaml">
Startup="Application_Startup">
<Application.Resources>

</Application.Resources>
Expand Down
96 changes: 95 additions & 1 deletion Permadelete.UpdateFactory/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -13,5 +16,96 @@ namespace Permadelete.UpdateFactory
/// </summary>
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
if (e.Args.Length > 0)
{
var argsList = e.Args.Select(a => a.ToLower()).ToList();

if (argsList.Contains("--help") || argsList.Contains("-help") || argsList.Contains("/?"))
{
Console.WriteLine(@"
Permadelete UpdateFactory
Used to make update config files for Permadelete.
ufactory -source <source path> [-output <output path>] [-link <change list link>] [-version <version>] [-type <update type>] [-target <target name>]
Paramters:
-source The full path of the folder that contains the binaries.
-output the full path of the folder to put the publish output in.
If not specified, then the output will be <source>\Publish
-link The link to a webpage that contains the full changelist of the current version
Default value is: https://github.com/encrypt0r/permadelete/releases
-version The version of the update. Default value is 1.0.0.0
-type The type of the update. Valid types: normal, critical
-target The name of the main application. It's used to get the version in it's not supplied.
Example:
ufactory -source D:\permadelete\Permadelete.FrontEnd\bin\Release -version 0.5.1
ufactory -source D:\permadelete\Permadelete.FrontEnd\bin\Release -output D:\permadelete\publish -target Permadelete.exe
");
Current.Shutdown();
return;
}

var sourceIndex = argsList.IndexOf("-source");
var linkIndex = argsList.IndexOf("-link");
var versionIndex = argsList.IndexOf("-version");
var targetIndex = argsList.IndexOf("-target");
var outputIndex = argsList.IndexOf("-output");
var typeIndex = argsList.IndexOf("-type");

var source = GetIfExists(argsList, sourceIndex, null);
if (source == null)
{
Console.WriteLine("You need to specify source.");
Current.Shutdown();
return;
}

var link = GetIfExists(argsList, linkIndex, "https://github.com/encrypt0r/permadelete/releases");
var version = GetIfExists(argsList, versionIndex, "1.0.0.0");
var output = GetIfExists(argsList, outputIndex, UpdateConfigManger.GetUniformPath(source, @"\Publish"));
var type = GetIfExists(argsList, typeIndex, "normal");
var targetName = GetIfExists(argsList, targetIndex, null);

if (targetName != null && version == "1.0.0.0")
{
version = FileVersionInfo.GetVersionInfo(UpdateConfigManger.GetUniformPath(source, targetName)).FileVersion;
}

var viewModel = UpdateConfigManger.Load(source);
viewModel.Version = version;
viewModel.Path = "data";
viewModel.Indented = false;
viewModel.Link = link;
viewModel.Type = type == "normal" ? Updater.UpdateType.Normal : Updater.UpdateType.Critical;

var updateInfo = UpdateConfigManger.GetUpdateInfo(viewModel.Path, viewModel.Type, viewModel.Link, viewModel.Version);
UpdateConfigManger.Write(output, viewModel.Files, viewModel.Indented ? Formatting.Indented : Formatting.None, updateInfo);

Console.WriteLine("Published successfuly to: " + output);
Current.Shutdown();
return;
}
else
{
MainWindow = new MainWindow();
MainWindow.Show();
}
}

private static string GetIfExists(List<string> args, int index, string fallback)
{
if (index == -1 || args.Count == index + 1)
return fallback;
else
return args[index + 1];
}
}
}
85 changes: 3 additions & 82 deletions Permadelete.UpdateFactory/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Permadelete.UpdateFactory
/// </summary>
public partial class MainWindow : Window
{
private static System.Text.RegularExpressions.Regex _pattern = new System.Text.RegularExpressions.Regex(@"[\\/]{2,}|[\\]");
private string _appFolderPath = string.Empty;
public MainWindow()
{
Expand All @@ -42,49 +41,8 @@ private void openButton_Click(object sender, RoutedEventArgs e)
if (result == null | !(bool)result) return;

_appFolderPath = dialog.SelectedPath;
var viewModel = new MainWindowVM();
var entries = System.IO.Directory.EnumerateFiles(_appFolderPath, "*.*", System.IO.SearchOption.AllDirectories);
var files = new ObservableCollection<FileVM>();
viewModel.Files = files;

viewModel.Version = "1.0.0.0";
viewModel.Link = "http://developerstree.com/";
viewModel.Path = "data";
viewModel.Type = UpdateType.Normal;

foreach (var item in entries)
{
if (item.EndsWith(".pdb") || item.Contains("vshost"))
continue;
var file = new FileVM();
file.FileInfo = new System.IO.FileInfo(item);
viewModel.Length += file.FileInfo.Length;
file.Name = file.FileInfo.Name;
var dirName = System.IO.Path.GetDirectoryName(item);
file.Folder = dirName.Replace(_appFolderPath, string.Empty).Replace(@"\", @"/");
var version = FileVersionInfo.GetVersionInfo(item).FileVersion;
if (version != null)
{
var count = version.Split('.').Count();
if (count != 4)
{
for (; count < 4; count++)
{
version += ".0";
}
}

file.Version = version;
}
else
file.Version = "1.0.0.0";
file.Length = file.FileInfo.Length;
file.IsIncluded = !file.Name.EndsWith(".xml");
file.Overwrite = item.EndsWith(".exe") || item.EndsWith(".dll") ? false : true;
files.Add(file);
}

DataContext = viewModel;
DataContext = UpdateConfigManger.Load(_appFolderPath);
}

private void publishButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -101,47 +59,10 @@ private void publishButton_Click(object sender, RoutedEventArgs e)
var path = dialog.SelectedPath;

var viewModel = (MainWindowVM)DataContext;
var updateInfo = new UpdateInfo();
var includedFiles = viewModel.Files.Where(f => f.IsIncluded);

updateInfo.Version = new Version(viewModel.Version);
updateInfo.Path = viewModel.Path;
updateInfo.Type = viewModel.Type;
updateInfo.Length = includedFiles.Sum(f => f.Delete ? 0 : f.FileInfo.Length);
updateInfo.ChangeListLink = viewModel.Link;
updateInfo.NewFiles = includedFiles.Where(f => f.Delete == false).Select(f => f.File).ToList();
updateInfo.ObsoleteFiles = includedFiles.Where(f => f.Delete).Select(f => GetUniformPath(f.Folder, f.Name)).ToList();
var format = viewModel.Indented ? Formatting.Indented : Formatting.None;
var json = JsonConvert.SerializeObject(updateInfo, format);

if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path);
System.IO.File.WriteAllText(GetUniformPath(path, "info.json"), json);
foreach (var file in includedFiles)
{
if (file.Delete)
continue;
var folderName = GetUniformPath(path, updateInfo.Path, file.Folder);
if (!System.IO.Directory.Exists(folderName))
System.IO.Directory.CreateDirectory(folderName);
file.FileInfo.CopyTo(GetUniformPath(folderName, file.Name), true);
}
var updateInfo = UpdateConfigManger.GetUpdateInfo(viewModel.Path, viewModel.Type, viewModel.Link, viewModel.Version);
UpdateConfigManger.Write(path, viewModel.Files, viewModel.Indented ? Formatting.Indented : Formatting.None, updateInfo);

Process.Start(path);
}

private static string GetUniformPath(params string[] segments)
{
string fullPath = string.Join("/", segments);
return _pattern.Replace(fullPath, "/");
}

private static string GetRelativePath(string parentFolder, string fullPath)
{
var result = fullPath.Replace(parentFolder, string.Empty);
if (result.Any() && result.First() == '\\' || result.First() == '/')
result = result.Substring(1);
return GetUniformPath(result);
}
}
}
2 changes: 1 addition & 1 deletion Permadelete.UpdateFactory/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Permadelete.UpdateFactory
{
class MainWindowVM : BindableBase
public class MainWindowVM : BindableBase
{
#region Constructor
public MainWindowVM()
Expand Down
15 changes: 9 additions & 6 deletions Permadelete.UpdateFactory/Permadelete.UpdateFactory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0649E428-72E8-4F36-B031-34F12CBF78F5}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Permadelete.UpdateFactory</RootNamespace>
<AssemblyName>Permadelete.UpdateFactory</AssemblyName>
<AssemblyName>ufactory</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand All @@ -26,7 +26,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Classic|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
Expand All @@ -39,9 +39,8 @@
<StartupObject>Permadelete.UpdateFactory.App</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Ookii.Dialogs.Wpf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0c15020868fd6249, processorArchitecture=MSIL">
<HintPath>..\packages\Ookii.Dialogs.1.0\lib\net35\Ookii.Dialogs.Wpf.dll</HintPath>
Expand Down Expand Up @@ -71,6 +70,7 @@
<Compile Include="DelegateCommand.cs" />
<Compile Include="FileVM.cs" />
<Compile Include="MainWindowVM.cs" />
<Compile Include="UpdateConfigManger.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -119,6 +119,9 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y $(TargetDir) $(SolutionDir)\Publish\ufactory</PostBuildEvent>
</PropertyGroup>
<!-- 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.
<Target Name="BeforeBuild">
Expand Down
Loading

0 comments on commit eae7371

Please sign in to comment.