Skip to content

Commit

Permalink
Many improvements, ready for beta
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsen9026 committed May 19, 2023
1 parent bb8ecc6 commit 9ec75c3
Show file tree
Hide file tree
Showing 31 changed files with 790 additions and 169 deletions.
38 changes: 38 additions & 0 deletions BlazamSetup/BlazamSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,16 @@
<Compile Include="Steps\DownloadInstallation.xaml.cs">
<DependentUpon>DownloadInstallation.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\ExitStep.xaml.cs">
<DependentUpon>ExitStep.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\IInstallationStep.cs" />
<Compile Include="Steps\IISPrerequisiteCheck.xaml.cs">
<DependentUpon>IISPrerequisiteCheck.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\InsallationProgressDisplay.xaml.cs">
<DependentUpon>InsallationProgressDisplay.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\Install.xaml.cs">
<DependentUpon>Install.xaml</DependentUpon>
</Compile>
Expand All @@ -429,6 +435,15 @@
<Compile Include="Steps\LicenseAgreement.xaml.cs">
<DependentUpon>LicenseAgreement.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\PostInstallation.xaml.cs">
<DependentUpon>PostInstallation.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\Repair\Repair.xaml.cs">
<DependentUpon>Repair.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\Repair\WelcomeRepair.xaml.cs">
<DependentUpon>WelcomeRepair.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\ServicePrerequisite.xaml.cs">
<DependentUpon>ServicePrerequisite.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -487,10 +502,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\ExitStep.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\IISPrerequisiteCheck.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\InsallationProgressDisplay.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\Install.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -511,6 +534,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\PostInstallation.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\Repair\Repair.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\Repair\WelcomeRepair.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\ServicePrerequisite.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -603,6 +638,9 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\nssm.exe" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.6.5.5\build\Fody.targets" Condition="Exists('..\packages\Fody.6.5.5\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
6 changes: 4 additions & 2 deletions BlazamSetup/Data/InstallationConfiguraion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ internal static class InstallationConfiguraion
/// <summary>
/// This value identifies the application, it should never change
/// </summary>
internal static string ProductGuid => "44f8501a-c549-4b27-8216-48480c65bc31";
internal static string ProductGuid => "44f8501a-c549-4b27-8216-48480c65bc31".ToUpper();
/// <summary>
/// This value identifies the version of the installer that was used, it should change every update.
/// </summary>
internal static string UpdateGuid => "a146351b-8ff5-457e-9aac-c6604a21bd1b";
internal static string UpdateGuid => "a146351b-8ff5-457e-9aac-c6604a21bd1b".ToUpper();

internal static ProductInformation ProductInformation { get; set; } = new ProductInformation();

Expand Down Expand Up @@ -52,5 +52,7 @@ internal static string InstallDirPath
public static string SetupTempDirectory => Path.GetTempPath() + "BlazamSetup\\";

public static InstalledAction InstalledAction { get; internal set; }
public static string InstalledVersion { get; internal set; }
public static bool ExecutableExists => File.Exists(ProductInformation.InstallLocation + Path.DirectorySeparatorChar + "Blazam.exe");
}
}
15 changes: 14 additions & 1 deletion BlazamSetup/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -40,8 +41,11 @@ public MainWindow()
NextStepButton = NextButton;
MainWindow.InstallerFrame.ContentRendered += InstallerFrame_ContentRendered;
if (RegistryService.InstallationExists)
{
InstallationConfiguraion.ProductInformation = RegistryService.GetProductInformation();


InstallationConfiguraion.InstalledVersion = FileSystemService.GetFileVersion(InstallationConfiguraion.ProductInformation.InstallLocation);
}
if (App.StartupArgs.Args.Any(arg => arg.StartsWith("/u")))
{
Log.Information("Uninstaller Started");
Expand Down Expand Up @@ -163,5 +167,14 @@ internal static void DisableBack()

});
}

internal static void SetNextText(string text)
{
CurrentDispatcher.Invoke(() =>
{
NextStepButton.Content = text;

});
}
}
}
10 changes: 10 additions & 0 deletions BlazamSetup/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions BlazamSetup/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@
<data name="minimize" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\minimize.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="nssm" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\nssm.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
Binary file added BlazamSetup/Resources/nssm.exe
Binary file not shown.
20 changes: 1 addition & 19 deletions BlazamSetup/Services/AppSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class AppSettingsService
public static bool Configure()
{

string path = InstallationConfiguraion.InstallDirPath + @"Blazam\\";
string path = Path.GetFullPath(InstallationConfiguraion.InstallDirPath + @"\\Blazam\\");


string jsonString = System.IO.File.ReadAllText(path+"appsettings.json");
Expand All @@ -41,24 +41,6 @@ public static bool Configure()
File.WriteAllText(Path.Combine(path, "appsettings.json"), newJson.ToString());


//var builder = new ConfigurationBuilder()
// .SetBasePath(path)
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
//var configuration = builder.Build();
//configuration["EncryptionKey"] = RandomString();
//configuration["HTTPPort"] = InstallationConfiguraion.WebHostConfiguration.HttpPort.ToString();
//configuration["HTTPPort"] = InstallationConfiguraion.WebHostConfiguration.HttpsPort.ToString();
//configuration["ListeningAddress"] = InstallationConfiguraion.WebHostConfiguration.ListeningAddress;
//configuration["DatabaseType"] = InstallationConfiguraion.DatabaseType.ToString();
//configuration["ConnectionStrings:DBConnectionString"] = InstallationConfiguraion.DatabaseConfiguration.ToAppSettingsString();
////File.WriteAllText(Path.Combine(path, "appsettings.json"), configuration.ToString());
//// Save changes to appsettings.json
//using (var stream = new FileStream("appsettings.json", FileMode.OpenOrCreate))
//{
// var json = JsonConvert.SerializeObject(configuration.AsEnumerable().ToList(), Formatting.Indented);
// var str = configuration.ToString();
// //configuration.Save(stream);
//}
return true;
}

Expand Down
77 changes: 76 additions & 1 deletion BlazamSetup/Services/FileSystemService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
Expand Down Expand Up @@ -31,5 +33,78 @@ public static bool AddPermission(string path, string identity, FileSystemRights
return true;
}

public static bool CopyDirectory(string source, string destination, ref AppEvent<double> progressEvent)
{

try
{
Log.Information("File copy started");

bool copyingDownTree = false;
if (destination.Contains(source))
{
copyingDownTree = true;
}
var totalFiles = FileSystemService.GetFileCount(source);
var fileIndex = 0;

if (Directory.Exists(source))
{
var directories = Directory.GetDirectories(source, "*", SearchOption.AllDirectories).AsEnumerable();

if (copyingDownTree)
directories = directories.Where(d => !d.Contains(destination));

//Now Create all of the directories
foreach (string dirPath in directories)
{
Log.Information("Creating directory: " + dirPath);

Directory.CreateDirectory(dirPath.Replace(source, destination));
}
var files = Directory.GetFiles(source, "*.*", SearchOption.AllDirectories).AsEnumerable();

if (copyingDownTree)
files = files.Where(f => !f.Contains(destination));
//Copy all the files & Replaces any files with the same name
foreach (string path in files)
{
var newPath = path.Replace(source, destination);
Log.Information("Copying file: " + newPath);

File.Copy(path, newPath, true);
fileIndex++;
progressEvent?.Invoke((fileIndex / totalFiles) * 100);
}
return true;

}
}
catch (Exception ex)
{
Log.Error("Error Copying files {@Error}", ex);

Console.WriteLine(ex.Message);
}
return false;
}

internal static string GetFileVersion(string installLocation)
{
try
{
if (File.Exists(installLocation))
{
return FileVersionInfo.GetVersionInfo(installLocation).ProductVersion;

}

}
catch (Exception ex)
{
Log.Error("Error getting file version {@Exception}", ex);
}
return "";
}
}
}
59 changes: 58 additions & 1 deletion BlazamSetup/Services/IISManageer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,63 @@ public static bool CreateApplication()
}
return false;
}


internal static bool RemoveApplication()
{
try
{
using (ServerManager serverManager = new ServerManager())
{
Log.Information("IIS Connected");
string httpBinding = InstallationConfiguraion.WebHostConfiguration.ListeningAddress + ":" + InstallationConfiguraion.WebHostConfiguration.HttpPort + ":";
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Blazam");
if (site is null)
{
return true;
}

Log.Information("Deleting IIS Site {@Site}", site);
serverManager.Sites.Remove(site);
serverManager.CommitChanges();


return true;
}
}
catch (Exception ex)
{
Log.Error("Error while removing IIS website. {@Error}", ex);
}
return false;
}

internal static bool Start()
{
try
{
using (ServerManager serverManager = new ServerManager())
{
Log.Information("IIS Connected");
string httpBinding = InstallationConfiguraion.WebHostConfiguration.ListeningAddress + ":" + InstallationConfiguraion.WebHostConfiguration.HttpPort + ":";
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Blazam");
if (site is null)
{
Log.Error("Tried to start site when it doesn't exist");

return false;
}

Log.Information("IIS Site {@Site}", site);

site.Start();
return true;
}
}
catch (Exception ex)
{
Log.Error("Error while starting IIS website. {@Error}", ex);
}
return false;
}
}
}
Loading

0 comments on commit 9ec75c3

Please sign in to comment.