Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net8 #4

Merged
merged 4 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
build:

runs-on: windows-latest
runs-on: windows-2019

steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 14 additions & 0 deletions BlazamSetup/BlazamSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@
<Compile Include="Steps\PostInstallation.xaml.cs">
<DependentUpon>PostInstallation.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\Update\Update.xaml.cs">
<DependentUpon>Update.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\Update\WelcomeUpdate.xaml.cs">
<DependentUpon>WelcomeUpdate.xaml</DependentUpon>
</Compile>
<Compile Include="Steps\Repair\Repair.xaml.cs">
<DependentUpon>Repair.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -538,6 +544,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Steps\Update\Update.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Steps\Update\WelcomeUpdate.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Steps\Repair\Repair.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
5 changes: 4 additions & 1 deletion BlazamSetup/Data/DatabaseConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public class DatabaseConfiguration
public int Port { get; set; }
public string Database { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string Password {
get;
set;
}
public string ValidationMessage
{
get
Expand Down
8 changes: 4 additions & 4 deletions BlazamSetup/Data/InstallationConfiguraion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class InstallationConfiguraion
/// <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".ToUpper();
internal static string UpdateGuid => "410dd7f9-001d-4916-a991-5ca86987b709".ToUpper();

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

Expand All @@ -39,9 +39,9 @@ internal static string InstallDirPath
{
get => installDirPath; set
{
installDirPath = value;
ProductInformation.InstallLocation = Path.GetFullPath(value+"\\Blazam");
ProductInformation.UninstallString = '"'+Path.GetFullPath(value+"\\Blazam\\setup.exe")+"\" /u";
installDirPath = Path.GetFullPath(value + "\\");
ProductInformation.InstallLocation = Path.GetFullPath(value+"\\");
ProductInformation.UninstallString = '"'+Path.GetFullPath(value+"\\setup.exe")+"\" /u";
}
}
internal static DatabaseConfiguration DatabaseConfiguration { get; set; } = new DatabaseConfiguration();
Expand Down
2 changes: 1 addition & 1 deletion BlazamSetup/Data/ProductInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class ProductInformation
{
public string DisplayName { get; set; } = "Blazam";
public string Publisher { get; set; } = "blazam.org";
public string DisplayVersion { get; set; } = "0.8";
public string DisplayVersion { get; set; } = "1.0";
public string Comments { get; set; } = " A web based Active Directry management portal";
public int NoRepair { get; set; } = 0;
public int NoModify { get; set; } = 1;
Expand Down
10 changes: 2 additions & 8 deletions BlazamSetup/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BlazamSetup
Expand All @@ -43,8 +37,8 @@ public MainWindow()
if (RegistryService.InstallationExists)
{
InstallationConfiguraion.ProductInformation = RegistryService.GetProductInformation();

InstallationConfiguraion.InstalledVersion = FileSystemService.GetFileVersion(InstallationConfiguraion.ProductInformation.InstallLocation);
InstallationConfiguraion.InstallDirPath = RegistryService.InstallLocation;
InstallationConfiguraion.InstalledVersion = FileSystemService.GetFileVersion(InstallationConfiguraion.ProductInformation.InstallLocation+"\\Blazam.exe");
}
if (App.StartupArgs.Args.Any(arg => arg.StartsWith("/u")))
{
Expand Down
6 changes: 3 additions & 3 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 = Path.GetFullPath(InstallationConfiguraion.InstallDirPath + @"\\Blazam\\");
string path = Path.GetFullPath(InstallationConfiguraion.InstallDirPath);


string jsonString = System.IO.File.ReadAllText(path+"appsettings.json");
Expand All @@ -46,8 +46,8 @@ public static bool Configure()

internal static void Copy()
{
string exampleFilePath = InstallationConfiguraion.InstallDirPath + "\\Blazam\\appsettings.example.json";
string filePath = InstallationConfiguraion.InstallDirPath + "\\Blazam\\appsettings.json";
string exampleFilePath = Path.GetFullPath(InstallationConfiguraion.InstallDirPath + "\\appsettings.example.json");
string filePath = Path.GetFullPath(InstallationConfiguraion.InstallDirPath + "\\appsettings.json");

if (File.Exists(exampleFilePath))
File.Copy(exampleFilePath, filePath,true);
Expand Down
121 changes: 66 additions & 55 deletions BlazamSetup/Services/DownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,106 +19,114 @@ internal static class DownloadService
public static string SetupTempDirectory = Path.GetTempPath() + "BlazamSetup\\";
public static string SourceDirectory = Path.GetTempPath() + "BlazamSetup\\setup\\";
public static string UpdateFile = SetupTempDirectory + "blazam.zip";
private static ReleaseAsset latestRelease;
public static ReleaseAsset LatestRelease;

public static int ExpectedSize { get; private set; }
public static CancellationTokenSource cancellationTokenSource { get; private set; } = new CancellationTokenSource();
public static int CompletedBytes { get; private set; }
public static InstallEvent<int> DownloadPercentageChanged { get; set; }

public static async Task<bool> Download()
public static async Task<bool> Download(string version=null)
{
Log.Information("Download started");

var githubclient = new GitHubClient(new ProductHeaderValue("BLAZAM-APP"));



var branch = "stable";
var branch = "Release";
//Get the releases from the repo
var releases = await githubclient.Repository.Release.GetAll("Blazam-App", "Blazam");
//Filter the releases to the selected branch
var branchReleases = releases.Where(r => r.TagName.ToLower().Contains(branch));
var branchReleases = releases.Where(r => r.TagName.ToLower().Contains(branch)|| r.TagName.ToLower().Contains("stable"));
//Get the first release,which should be the most recent
latestRelease = branchReleases.FirstOrDefault()?.Assets.FirstOrDefault();
LatestRelease = branchReleases.FirstOrDefault()?.Assets.FirstOrDefault();
//Get the release filename to prepare a version object
var filename = Path.GetFileNameWithoutExtension(latestRelease.Name);
var filename = Path.GetFileNameWithoutExtension(LatestRelease.Name);
//Create that version object
if (filename == null) throw new ApplicationUpdateException("Filename could not be retrieved from GitHub");




if (version != null)
{
var matchingRelease = releases.Where(r=>r.TagName.ToLower().Contains(version)).FirstOrDefault();
if(matchingRelease != null)
{
return await DownloadAsset(matchingRelease.Assets.FirstOrDefault());

if (latestRelease != null)
}
throw new ApplicationUpdateException("Could not find requested version number. Try running an update.");
}
else if (LatestRelease != null)
{
return await DownloadAsset(LatestRelease);

}
return false;
}

using (var client = new HttpClient())
private static async Task<bool> DownloadAsset(ReleaseAsset releaseToDownload)
{
using (var client = new HttpClient())
{
using (var response = await client.GetAsync(releaseToDownload.BrowserDownloadUrl, HttpCompletionOption.ResponseHeadersRead))
{
using (var response = await client.GetAsync(latestRelease.BrowserDownloadUrl, HttpCompletionOption.ResponseHeadersRead))
if (!response.IsSuccessStatusCode)
{
if (!response.IsSuccessStatusCode)
{
//Loggers.UpdateLogger?.Debug("Unable to connect to download url: " + response.StatusCode + " : " + response.ReasonPhrase);
//Loggers.UpdateLogger?.Debug("Unable to connect to download url: " + response.StatusCode + " : " + response.ReasonPhrase);

return false;
}
return false;
}

if (File.Exists(UpdateFile))
{
if (Debugger.IsAttached)
{
return true;
}
else
{
File.Delete(UpdateFile);
}
if (File.Exists(UpdateFile))
{

File.Delete(UpdateFile);


}
using (var streamToReadFrom = await response.Content.ReadAsStreamAsync())
}
using (var streamToReadFrom = await response.Content.ReadAsStreamAsync())
{
Directory.CreateDirectory(SetupTempDirectory);
File.Create(UpdateFile).Close();
using (var streamToWriteTo = File.OpenWrite(UpdateFile))
{
Directory.CreateDirectory(SetupTempDirectory);
File.Create(UpdateFile).Close();
using (var streamToWriteTo = File.OpenWrite(UpdateFile))
{
ExpectedSize = (int)latestRelease.Size;
var buffer = new byte[262144];
//var buffer = new byte[4096];
int bytesRead;
int totalBytesRead = 0;
ExpectedSize = (int)releaseToDownload.Size;
var buffer = new byte[262144];
//var buffer = new byte[4096];
int bytesRead;
int totalBytesRead = 0;

while ((bytesRead = await streamToReadFrom.ReadAsync(buffer, 0, buffer.Length)) > 0)
while ((bytesRead = await streamToReadFrom.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
if (!cancellationTokenSource.IsCancellationRequested)
{
await streamToWriteTo.WriteAsync(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
CompletedBytes = totalBytesRead;
var percentage = (CompletedBytes / (double)ExpectedSize * 100);
DownloadPercentageChanged?.Invoke((int)percentage);
}
else
{
if (!cancellationTokenSource.IsCancellationRequested)
{
await streamToWriteTo.WriteAsync(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
CompletedBytes = totalBytesRead;
var percentage = (CompletedBytes / (double)ExpectedSize * 100);
DownloadPercentageChanged?.Invoke((int)percentage);
}
else
{
streamToReadFrom.Close();
DownloadPercentageChanged?.Invoke(0);

return false;
}
streamToReadFrom.Close();
DownloadPercentageChanged?.Invoke(0);

return false;
}
}

return true;
return true;


}
}
}
}

}
return false;
}

public static void CleanDownload()
{

Expand Down Expand Up @@ -180,18 +188,21 @@ internal static async Task<bool> UnpackDownload()
Log.Information("Extracting files: " + SourceDirectory);

CleanSource();

Directory.CreateDirectory(SourceDirectory);
ZipArchive download = new ZipArchive(File.OpenRead(UpdateFile));
download.ExtractToDirectory(SourceDirectory);
download.Dispose();
File.Delete(UpdateFile);
return true;

}
catch (Exception ex)
{
Log.Error("Error unpacking download: {@Error}", ex);

}

return false;
});

Expand Down
4 changes: 3 additions & 1 deletion BlazamSetup/Services/FileSystemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ internal static string GetFileVersion(string installLocation)
{
if (File.Exists(installLocation))
{
return FileVersionInfo.GetVersionInfo(installLocation).ProductVersion;
var fvi = FileVersionInfo.GetVersionInfo(installLocation);
string version = fvi.FileVersion+"."+fvi.ProductVersion;
return version;

}

Expand Down
4 changes: 2 additions & 2 deletions BlazamSetup/Services/IISManageer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public static bool CreateApplication()
site = serverManager.Sites.Add("Blazam",
"http",
httpBinding,
Path.GetFullPath(InstallationConfiguraion.InstallDirPath + @"\\Blazam\\"));
Path.GetFullPath(InstallationConfiguraion.InstallDirPath));
}

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

serverManager.CommitChanges();

FileSystemService.AddPermission(
Path.GetFullPath(InstallationConfiguraion.InstallDirPath + "\\Blazam\\"),
Path.GetFullPath(InstallationConfiguraion.InstallDirPath),
"IIS_IUSRS",
FileSystemRights.ReadAndExecute
);
Expand Down
Loading
Loading