3 Commits
1.2 ... 1.3

Author SHA1 Message Date
031da4cea9 Actualitzem Versió 2021-01-07 12:27:49 +01:00
7dcaaeae32 Traduccio al català 2021-01-07 12:11:10 +01:00
38edd8f399 Afegir Actualitzacions automatiques 2021-01-07 12:08:16 +01:00
4 changed files with 309 additions and 8 deletions

View File

@@ -6,7 +6,8 @@
xmlns:local="clr-namespace:UtilitatPdf"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="Utilitats Pdf" Height="450" Width="550" Icon="pdf.ico" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
ContentRendered="CheckNewUpdates"
Title="UtilitatPdf 1.3" Height="450" Width="550" Icon="pdf.ico" WindowStartupLocation="CenterScreen" ResizeMode="NoResize">
<Window.Resources>
<Style x:Key="Opacity1" TargetType="Image">
<Style.Triggers>
@@ -101,7 +102,7 @@
<TextBlock Margin="50,10,0,0">- S'afegirà '-sense-signatura' al nom del fitxer i es desarà a la mateixa carpeta que</TextBlock>
<TextBlock Margin="60,5,0,0"> l'original.</TextBlock>
<CheckBox x:Name="CheckKeepSignature" Content="Mantenir signatures originals" Margin="20,20,0,0" HorizontalAlignment="Left"/>
<TextBlock Margin="50,10,0,0">- Si s'activa, seditaran les signatures però Adobe Reader donarà error de signatures</TextBlock>
<TextBlock Margin="50,10,0,0">- Si s'activa, seditaran les signatures, però Adobe Reader donarà error de signatures</TextBlock>
<TextBlock Margin="60,5,0,0">degut a que l'arxiu s'ha modificat desprès dhaver-lo signat.</TextBlock>
<Button Margin="0,20,0,0" Height="30" Width="180" HorizontalAlignment="Center" Click="RemoveSign_Button_Click">Treure Signatura</Button>
</StackPanel>

View File

@@ -18,8 +18,7 @@ using Rectangle = iText.Kernel.Geom.Rectangle;
using System.Windows.Controls;
using Canvas = iText.Layout.Canvas;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using UtilitatPdf.CheckUpdates;
namespace UtilitatPdf
{
@@ -34,6 +33,22 @@ namespace UtilitatPdf
{
InitializeComponent();
}
async void CheckNewUpdates(object sender, EventArgs e)
{
Updater needUpdate = new Updater();
if (needUpdate.IsNewerVersion)
{
MessageBoxResult result = MessageBox.Show("Hi Ha disponible una nova versió de l'aplicació.\n Actual: "+ needUpdate.CurrentVersion +" Nova Versió: " + needUpdate.NewReleaseVersion + "\n\nVols Actualizarla ara?", "Actualització", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
await needUpdate.DownloadReleaseAsync();
if (needUpdate.DownloadComplete) needUpdate.UpdateSelf();
}
}
}
#region ButtonText
private void SelectOpenFile_Button_Click(object sender, RoutedEventArgs e)
{
@@ -241,6 +256,7 @@ namespace UtilitatPdf
{
string patronCif = @"([a-zA-Z]-?[0-9]{8})";
string patronNif = @"([0-9]{8}-?[a-zA-Z])";
string replaceWith = "<NIF_EDITAT>";
string cleanRegex = string.Empty;
string widgetText = string.Empty;
bool doneOk = false;
@@ -273,9 +289,8 @@ namespace UtilitatPdf
if (matchesCif.Count > 0 || matchesNif.Count > 0)
{
cleanRegex = Regex.Replace(widgetText, patronCif, "<NIF_EDITAT>");
cleanRegex = Regex.Replace(cleanRegex, patronNif, "<NIF_EDITAT>");
cleanRegex = Regex.Replace(widgetText, patronCif, replaceWith);
cleanRegex = Regex.Replace(cleanRegex, patronNif, replaceWith);
PdfArray annotationRect = pdfWidgetAnnotation.GetRectangle();
pdfWidgetAnnotation.SetRectangle(annotationRect);
@@ -334,7 +349,6 @@ namespace UtilitatPdf
OutSignFile.IsEnabled = true;
SelectFile6.IsEnabled = true;
}
} // END Window Class
} // END Namespace

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Globalization;
namespace UtilitatPdf.CheckUpdates
{
public partial class Gitea
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("tag_name")]
public string TagName { get; set; }
[JsonProperty("target_commitish")]
public string TargetCommitish { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("body")]
public string Body { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
[JsonProperty("html_url")]
public Uri HtmlUrl { get; set; }
[JsonProperty("tarball_url")]
public Uri TarballUrl { get; set; }
[JsonProperty("zipball_url")]
public Uri ZipballUrl { get; set; }
[JsonProperty("draft")]
public bool Draft { get; set; }
[JsonProperty("prerelease")]
public bool Prerelease { get; set; }
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonProperty("published_at")]
public DateTimeOffset PublishedAt { get; set; }
[JsonProperty("author")]
public Author Author { get; set; }
[JsonProperty("assets")]
public List<Asset> Assets { get; set; }
}
public partial class Asset
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("size")]
public long Size { get; set; }
[JsonProperty("download_count")]
public long DownloadCount { get; set; }
[JsonProperty("created_at")]
public DateTimeOffset CreatedAt { get; set; }
[JsonProperty("uuid")]
public Guid Uuid { get; set; }
[JsonProperty("browser_download_url")]
public Uri BrowserDownloadUrl { get; set; }
}
public partial class Author
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("login")]
public string Login { get; set; }
[JsonProperty("full_name")]
public string FullName { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
[JsonProperty("avatar_url")]
public Uri AvatarUrl { get; set; }
[JsonProperty("language")]
public string Language { get; set; }
[JsonProperty("is_admin")]
public bool IsAdmin { get; set; }
[JsonProperty("last_login")]
public DateTimeOffset LastLogin { get; set; }
[JsonProperty("created")]
public DateTimeOffset Created { get; set; }
[JsonProperty("username")]
public string Username { get; set; }
}
public partial class Gitea
{
public static List<Gitea> FromJson(string json) => JsonConvert.DeserializeObject<List<Gitea>>(json, UtilitatPdf.CheckUpdates.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this List<Gitea> self) => JsonConvert.SerializeObject(self, UtilitatPdf.CheckUpdates.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters =
{
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
}

View File

@@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Path = System.IO.Path;
namespace UtilitatPdf.CheckUpdates
{
class Updater
{
public bool IsNewerVersion { get; private set; }
public string NewReleaseVersion { get; private set; }
public float DownloadProgress { get; private set; }
public long BytesReceived { get; private set; }
public long RemainingBytes { get; private set; }
public string UserState { get; private set; }
public bool DownloadComplete { get { return _downloadComplete; } private set { value = _downloadComplete; } }
public string CurrentVersion { get { return _currentVersion; } }
private static string _currentVersion = "1.3";
private string _downloadRelease = _currentVersion;
private static HttpClient Client = new HttpClient();
private Uri _urlDescarga = null;
private bool _downloadComplete = false;
private List<Gitea> llistaIds = new List<Gitea>();
private static string self = Process.GetCurrentProcess().MainModule.FileName;
private static string selfFileName = Path.GetFileName(self);
private static string selfWithoutExt = Path.Combine(Path.GetDirectoryName(self), Path.GetFileNameWithoutExtension(self));
public Updater()
{
this.GetItems();
this.CheckForUpdates();
}
private void CheckForUpdates()
{
foreach (Gitea releases in llistaIds)
{
var version1 = new Version(_downloadRelease);
var version2 = new Version(releases.TagName);
var result = version1.CompareTo(version2);
if (result < 0)
{
_downloadRelease = releases.TagName;
List<Asset> assets = releases.Assets;
foreach (Asset asset in assets)
{
_urlDescarga = asset.BrowserDownloadUrl;
}
}
}
if (_currentVersion != _downloadRelease)
{
IsNewerVersion = true;
NewReleaseVersion = _downloadRelease;
}
}
private void GetItems()
{
string url = $"https://git.vconesa.net/api/v1/repos/amorfo77/UtilitatPdf/releases";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "application/json";
request.Accept = "application/json";
try
{
using (WebResponse response = request.GetResponse())
{
using (Stream strReader = response.GetResponseStream())
{
if (strReader == null) return;
using (StreamReader objReader = new StreamReader(strReader))
{
string responseBody = objReader.ReadToEnd();
llistaIds = Gitea.FromJson(responseBody);
}
}
}
}
catch (WebException)
{
throw new WebException();
}
}
public async Task DownloadReleaseAsync()
{
_downloadComplete = false;
try
{
var response = await Client.GetAsync(_urlDescarga);
response.EnsureSuccessStatusCode();
using (var stream = await response.Content.ReadAsStreamAsync())
{
var fileInfo = new FileInfo(selfWithoutExt + "Update.exe");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
}
_downloadComplete = true;
}
catch (Exception)
{
throw new Exception();
}
}
public void UpdateSelf()
{
if (Environment.OSVersion.Platform == PlatformID.Unix ||
Environment.OSVersion.Platform == PlatformID.MacOSX)
{
Process.Start(self);
// Sleep for half a second to avoid an exception
Thread.Sleep(500);
Environment.Exit(0);
}
else
{
using (var batFile = new StreamWriter(File.Create(selfWithoutExt + "Update.bat")))
{
batFile.WriteLine("@ECHO OFF");
batFile.WriteLine("TIMEOUT /t 1 /nobreak > NUL");
batFile.WriteLine("TASKKILL /IM \"{0}\" > NUL", selfFileName);
batFile.WriteLine("MOVE \"{0}\" \"{1}\"", selfWithoutExt + "Update.exe", self);
batFile.WriteLine("DEL \"%~f0\" & START \"\" /B \"{0}\"", self);
}
ProcessStartInfo startInfo = new ProcessStartInfo(selfWithoutExt + "Update.bat");
// Hide the terminal window
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = Path.GetDirectoryName(self);
Process.Start(startInfo);
Environment.Exit(0);
}
}
}
}