1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-14 12:15:48 +02:00

Include version header in ScriptLoader files to detect failed installs

This commit is contained in:
chylex 2018-04-03 23:44:43 +02:00
parent e9de789b79
commit 812a034e8d
2 changed files with 36 additions and 6 deletions

View File

@ -3,6 +3,9 @@ $ErrorActionPreference = "Stop"
Set-Location $dir
$version = (Get-Item TweetDuck.exe).VersionInfo.FileVersion
Write-Host "TweetDuck version" $version
function Check-Carriage-Return{
Param([Parameter(Mandatory = $True, Position = 1)] $fname)
@ -19,8 +22,14 @@ function Rewrite-File{
[CmdletBinding()]
Param([Parameter(Mandatory = $True, ValueFromPipeline = $True)][array] $lines, [Parameter(Mandatory = $True, Position = 1)] $file)
$relative = $file.FullName.Substring($dir.Length)
if ($relative.StartsWith("scripts\")){
$lines = (,("#" + $version) + $lines)
}
$lines | Where { $_ -ne '' } | Set-Content -Path $file.FullName
Write-Host "Processed" $file.FullName.Substring($dir.Length)
Write-Host "Processed" $relative
}
try{

View File

@ -12,12 +12,29 @@ static class ScriptLoader{
public static string LoadResource(string name, bool silent = false, Control sync = null){
try{
return File.ReadAllText(Path.Combine(Program.ScriptPath, name), Encoding.UTF8);
}catch(Exception ex){
if (!silent){
ShowLoadError(sync, "Unfortunately, TweetDuck could not load the "+name+" file. The program will continue running with limited functionality.\n\n"+ex.Message);
string contents = File.ReadAllText(Path.Combine(Program.ScriptPath, name), Encoding.UTF8);
int separator;
// first line can be either:
// #<version>\r\n
// #<version>\n
if (contents[0] != '#'){
ShowLoadError(silent, sync, $"File {name} appears to be corrupted, please try reinstalling the app.");
separator = 0;
}
else{
separator = contents.IndexOf('\n');
string fileVersion = contents.Substring(1, separator-1).TrimEnd();
if (fileVersion != Program.VersionTag){
ShowLoadError(silent, sync, $"File {name} is made for a different version of TweetDuck ({fileVersion}) and may not function correctly in this version, please try reinstalling the app.");
}
}
return contents.Substring(separator).TrimStart();
}catch(Exception ex){
ShowLoadError(silent, sync, $"Could not load {name}. The program will continue running with limited functionality.\n\n{ex.Message}");
return null;
}
}
@ -38,7 +55,11 @@ public static string GetRootIdentifier(string file){
return "root:"+Path.GetFileNameWithoutExtension(file);
}
private static void ShowLoadError(Control sync, string message){
private static void ShowLoadError(bool silent, Control sync, string message){
if (silent){
return;
}
if (sync == null){
FormMessage.Error("TweetDuck Has Failed :(", message, FormMessage.OK);
}