From c89a04e1f5c19274dbf4a3e6d45a7c575243523c Mon Sep 17 00:00:00 2001 From: SioGabx <41244237+SioGabx@users.noreply.github.com> Date: Sun, 3 Sep 2023 13:23:39 +0200 Subject: [PATCH] Bug fixes Share layer button added into the edit page Copy and paste button on selection location popup Improve update system Prepare for release 0.5.1-alpha --- MapsInMyFolder.Common/Collectif.cs | 49 +- MapsInMyFolder.Common/Database.cs | 33 +- MapsInMyFolder.Common/Javascript.Functions.cs | 3 +- MapsInMyFolder.Common/Javascript.cs | 1 - MapsInMyFolder.Common/MessageContentDialog.cs | 5 +- MapsInMyFolder.Common/Update.cs | 41 +- MapsInMyFolder.Setup/Product.wxs | 2 +- MapsInMyFolder/CustomOrEditLayersPage.xaml | 20 +- MapsInMyFolder/CustomOrEditLayersPage.xaml.cs | 120 +- MapsInMyFolder/DownloadPannel.cs | 2 +- MapsInMyFolder/Languages/English.ini | 15 +- MapsInMyFolder/Languages/French.ini | 15 +- MapsInMyFolder/LayersPannel.cs | 161 +- MapsInMyFolder/MainPage.xaml | 2 +- MapsInMyFolder/MainPage.xaml.cs | 128 +- MapsInMyFolder/MapsInMyFolder.csproj | 2 +- MapsInMyFolder_Database.db | Bin 1716224 -> 1777664 bytes MapsInMyFolder_Database.txt | 1747 +++++++++++++++-- 18 files changed, 2042 insertions(+), 304 deletions(-) diff --git a/MapsInMyFolder.Common/Collectif.cs b/MapsInMyFolder.Common/Collectif.cs index c67073a..0ec8215 100644 --- a/MapsInMyFolder.Common/Collectif.cs +++ b/MapsInMyFolder.Common/Collectif.cs @@ -317,6 +317,27 @@ public static void RestartApplication() Application.Current.Shutdown(); } + public static void StartApplication(string path, TimeSpan delay) + { + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = "cmd.exe", + Arguments = $"/c timeout {delay.Seconds} & start /min \"\" \"{path}\"", + CreateNoWindow = true, // Ne pas créer de fenêtre CMD + UseShellExecute = false, // N'utilise pas le shell + RedirectStandardOutput = true, + RedirectStandardError = true + }; + + Process process = new Process + { + StartInfo = startInfo + }; + process.Start(); + } + + + public static SolidColorBrush HexValueToSolidColorBrush(string hexvalue, string defaulthexvalue = null) { if (!string.IsNullOrEmpty(hexvalue)) @@ -359,7 +380,8 @@ public static ScrollViewer FormatDiffGetScrollViewer(string texteBase, string te { MaxHeight = 200, Margin = new Thickness(0, 5, 0, 20), - VerticalScrollBarVisibility = ScrollBarVisibility.Auto + VerticalScrollBarVisibility = ScrollBarVisibility.Auto, + HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled }; StackPanel ScrollViewerElementContent = new StackPanel() { @@ -380,9 +402,9 @@ public static TextBlock FormatDiff(string texteBase, string texteModif) TextBlock ContentTextBlock = new TextBlock() { - TextWrapping = TextWrapping.WrapWithOverflow, + TextWrapping = TextWrapping.Wrap, Foreground = HexValueToSolidColorBrush("#FFE2E2E1"), - TextAlignment = TextAlignment.Justify + TextAlignment = TextAlignment.Justify, }; List diffs = dmp.diff_main(texteBase, texteModif); SolidColorBrush BackgroundGreen = HexValueToSolidColorBrush("#6b803f"); @@ -943,6 +965,27 @@ public static void LockPreviousUndo(TextBox uIElement) uIElement.UndoLimit = undo_limit; } + public static void ClickableLabel_MouseEnter(object sender, MouseEventArgs e) + { + Label label_element = sender as Label; + if (label_element.IsEnabled) + { + label_element.Cursor = Cursors.Hand; + label_element.Foreground = Collectif.HexValueToSolidColorBrush("#b4b4b4"); + } + else + { + label_element.Cursor = Cursors.Arrow; + } + } + + public static void ClickableLabel_MouseLeave(object sender, MouseEventArgs e) + { + Label label_element = sender as Label; + label_element.Foreground = Collectif.HexValueToSolidColorBrush("#888989"); + } + + public static void InsertTextAtCaretPosition(ICSharpCode.AvalonEdit.TextEditor TextBox, string text) { int CaretIndex = TextBox.CaretOffset; diff --git a/MapsInMyFolder.Common/Database.cs b/MapsInMyFolder.Common/Database.cs index a3f8224..7f0c5bf 100644 --- a/MapsInMyFolder.Common/Database.cs +++ b/MapsInMyFolder.Common/Database.cs @@ -141,7 +141,7 @@ public static async void DB_Download() CreateEmptyDatabase(database_pathname); } - static public SQLiteDataReader ExecuteExecuteReaderSQLCommand(string querry) + static public (SQLiteDataReader Reader, SQLiteConnection conn) ExecuteExecuteReaderSQLCommand(string querry) { bool HasError = false; do @@ -153,12 +153,12 @@ static public SQLiteDataReader ExecuteExecuteReaderSQLCommand(string querry) if (conn is null) { Debug.WriteLine("La connection à la base de donnée est null"); - return null; + return (null, null); } using (SQLiteCommand sqlite_cmd = conn.CreateCommand()) { sqlite_cmd.CommandText = querry; - return sqlite_cmd.ExecuteReader(); + return (sqlite_cmd.ExecuteReader(), conn); } } catch (Exception ex) @@ -174,7 +174,7 @@ static public SQLiteDataReader ExecuteExecuteReaderSQLCommand(string querry) } } } while (HasError); - return null; + return (null, null); } static public int ExecuteScalarSQLCommand(string querry) @@ -210,8 +210,10 @@ static public int ExecuteScalarSQLCommand(SQLiteConnection conn, string querry) static public int ExecuteNonQuerySQLCommand(string querry) { - using SQLiteConnection conn = DB_Connection(); - return ExecuteNonQuerySQLCommand(conn, querry); + using (SQLiteConnection conn = DB_Connection()) + { + return ExecuteNonQuerySQLCommand(conn, querry); + } } static public int ExecuteNonQuerySQLCommand(SQLiteConnection conn, string querry) @@ -539,7 +541,7 @@ public static void MergeDatabase(string downloadedDatabasePath) public static void FixEditedLayers() { - using (SQLiteDataReader editedlayers_sqlite_datareader = ExecuteExecuteReaderSQLCommand("SELECT * FROM 'EDITEDLAYERS'")) + using (SQLiteDataReader editedlayers_sqlite_datareader = ExecuteExecuteReaderSQLCommand("SELECT * FROM 'EDITEDLAYERS'").Reader) { StringBuilder SQLExecute = new StringBuilder(); SQLExecute.Append("BEGIN TRANSACTION;"); @@ -550,7 +552,7 @@ public static void FixEditedLayers() string EditedDB_SCRIPT = editedlayers_sqlite_datareader.GetStringFromOrdinal("SCRIPT"); string EditedDB_TILE_URL = editedlayers_sqlite_datareader.GetStringFromOrdinal("TILE_URL"); - using (SQLiteDataReader layers_sqlite_datareader = ExecuteExecuteReaderSQLCommand($"SELECT * FROM 'LAYERS' WHERE ID = {DB_Layer_ID}")) + using (SQLiteDataReader layers_sqlite_datareader = ExecuteExecuteReaderSQLCommand($"SELECT * FROM 'LAYERS' WHERE ID = {DB_Layer_ID}").Reader) { layers_sqlite_datareader.Read(); int LastDB_VERSION = layers_sqlite_datareader.GetIntFromOrdinal("VERSION") ?? 0; @@ -589,7 +591,7 @@ public static void CheckForMissingCollumns() foreach (string key in map.Keys) { - using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info({key})")) + using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info({key})").Reader) { while (LayersTables.Read()) { @@ -622,7 +624,7 @@ public static void CheckForMissingCollumns() SQLExecute.Append("BEGIN TRANSACTION;"); foreach (string key in map.Keys) { - using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info({key})")) + using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info({key})").Reader) { while (LayersTables.Read()) { @@ -653,14 +655,14 @@ public static void Export(string FilePath) StringBuilder SQLExecute = new StringBuilder(); SQLExecute.Append("BEGIN TRANSACTION;"); - using (SQLiteDataReader sqlite_datareader = ExecuteExecuteReaderSQLCommand("SELECT sql FROM 'main'.'sqlite_master' WHERE name = 'LAYERS';")) + using (SQLiteDataReader sqlite_datareader = ExecuteExecuteReaderSQLCommand("SELECT sql FROM 'main'.'sqlite_master' WHERE name = 'LAYERS';").Reader) { sqlite_datareader.Read(); SQLExecute.AppendLine(string.Concat(sqlite_datareader.GetString(0) + ";")); } Dictionary TableCollumsNames = new Dictionary(); - using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info(LAYERS)")) + using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info(LAYERS)").Reader) { while (LayersTables.Read()) { @@ -672,7 +674,7 @@ public static void Export(string FilePath) foreach (string Table in new string[2] { "LAYERS", "CUSTOMSLAYERS" }) { - using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"SELECT * FROM '{Table}';")) + using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"SELECT * FROM '{Table}';").Reader) { while (LayersTables.Read()) { @@ -703,7 +705,7 @@ public static void Export(string FilePath) ValuesList.Add(CollumnName, Collectif.HTMLEntities(Value)); } - using (SQLiteDataReader EditedLayersTables = ExecuteExecuteReaderSQLCommand($"SELECT * FROM 'EDITEDLAYERS' WHERE ID={RowId};")) + using (SQLiteDataReader EditedLayersTables = ExecuteExecuteReaderSQLCommand($"SELECT * FROM 'EDITEDLAYERS' WHERE ID={RowId};").Reader) { while (EditedLayersTables.Read()) { @@ -742,7 +744,8 @@ public static void Export(string FilePath) { IntLayerVersion = 0; } - ValuesList["VERSION"] = IntLayerVersion++.ToString(); + + ValuesList["VERSION"] = (IntLayerVersion + 1).ToString(); } } } diff --git a/MapsInMyFolder.Common/Javascript.Functions.cs b/MapsInMyFolder.Common/Javascript.Functions.cs index 6ff3403..5a1d981 100644 --- a/MapsInMyFolder.Common/Javascript.Functions.cs +++ b/MapsInMyFolder.Common/Javascript.Functions.cs @@ -1,5 +1,4 @@ using System; -using System.CodeDom; using System.Collections.Generic; using System.Diagnostics; using System.Text; @@ -299,7 +298,7 @@ static public string InputBox(int LayerId, object texte, object caption = null) var frame = new DispatcherFrame(); TextBox = Application.Current.Dispatcher.Invoke(new Func(() => { - var (textBox, dialog) = Message.SetInputBoxDialog(texte, caption); + var (textBox, dialog) = Message.SetInputBoxDialog(texte, string.Empty, caption); void Dialog_Closed(object sender, EventArgs e) { diff --git a/MapsInMyFolder.Common/Javascript.cs b/MapsInMyFolder.Common/Javascript.cs index b8b6b43..666486e 100644 --- a/MapsInMyFolder.Common/Javascript.cs +++ b/MapsInMyFolder.Common/Javascript.cs @@ -2,7 +2,6 @@ using Esprima.Ast; using Jint; using Jint.Native; -using MapsInMyFolder.VectorTileRenderer; using Newtonsoft.Json; using System; using System.Collections.Generic; diff --git a/MapsInMyFolder.Common/MessageContentDialog.cs b/MapsInMyFolder.Common/MessageContentDialog.cs index 86df243..046afc6 100644 --- a/MapsInMyFolder.Common/MessageContentDialog.cs +++ b/MapsInMyFolder.Common/MessageContentDialog.cs @@ -9,7 +9,7 @@ namespace MapsInMyFolder.Commun public static class Message { - public static (TextBox textBox, ContentDialog dialog) SetInputBoxDialog(object text, object caption = null, MessageDialogButton messageBoxButton = MessageDialogButton.OK) + public static (TextBox textBox, ContentDialog dialog) SetInputBoxDialog(object text, object textboxdefaultvalue = null, object caption = null, MessageDialogButton messageBoxButton = MessageDialogButton.OK) { if (string.IsNullOrEmpty(text?.ToString())) @@ -33,7 +33,8 @@ public static (TextBox textBox, ContentDialog dialog) SetInputBoxDialog(object t Style = (Style)Application.Current.Resources["TextBoxCleanStyleDefault"], HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0, 10, 0, 0), - Height = 25, + MinHeight = 25, + Text = textboxdefaultvalue.ToString() }; MessageContentDialogHelpers.FocusSenderOnLoad(textBox); StackPanel stackPanel = new StackPanel(); diff --git a/MapsInMyFolder.Common/Update.cs b/MapsInMyFolder.Common/Update.cs index 52d0bb2..d6c1b21 100644 --- a/MapsInMyFolder.Common/Update.cs +++ b/MapsInMyFolder.Common/Update.cs @@ -97,18 +97,18 @@ public static bool CompareVersion(string GithubVersion) public static async void StartUpdating() { - var dialog = Message.SetContentDialog(Languages.GetWithArguments("updateMessageNewVersionAvailable", UpdateRelease.Tag_name, UpdateRelease.Body), "Confirmer", MessageDialogButton.YesNo); - ContentDialogResult result2 = ContentDialogResult.None; + var dialog = Message.SetContentDialog(Languages.GetWithArguments("updateMessageNewVersionAvailable", UpdateRelease.Tag_name, UpdateRelease.Body), Languages.Current["dialogTitleOperationConfirm"], MessageDialogButton.YesNo); + ContentDialogResult result = ContentDialogResult.None; try { - result2 = await dialog.ShowAsync(); + result = await dialog.ShowAsync(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } - if (result2 != ContentDialogResult.Primary) + if (result != ContentDialogResult.Primary) { return; } @@ -130,11 +130,38 @@ public static async void StartUpdating() }); }; await client.StartDownload(); + UpdateNotification.Remove(); + + var dialog2 = Message.SetContentDialog(Languages.Current["updateMessageStartUpdateProcess"], Languages.Current["dialogTitleOperationConfirm"], MessageDialogButton.YesCancel); + ContentDialogResult result2 = ContentDialogResult.None; + try + { + result2 = await dialog2.ShowAsync(); + } + catch (Exception ex) + { + Debug.WriteLine(ex.ToString()); + } - UpdateNotification.Text(Languages.Current["updateNotificationStartInstalling"]); - UpdateNotification.SendUpdate(); + if (result2 == ContentDialogResult.Primary) + { + ApplyUpdate(); + } + else { + NText UpdateDownloadedNotification = new NText(Languages.Current["updateNotificationStartUpdateProcess"], "MapsInMyFolder", "MainPage", ApplyUpdate, true); + UpdateDownloadedNotification.Register(); + } + } + + public static void ApplyUpdate() + { + NText UpdateNotification = new NText(Languages.Current["updateNotificationStartInstalling"], "MapsInMyFolder", "MainPage", null, true); + UpdateNotification.Register(); + + string UpdateFilePath = System.IO.Path.Combine(Settings.temp_folder, UpdateFileAsset.Id + UpdateFileAsset.Name); + Collectif.StartApplication(UpdateFilePath, TimeSpan.FromSeconds(3)); Application.Current.Shutdown(); - Process.Start(new ProcessStartInfo(UpdateFilePath) { UseShellExecute = true }); } + } } diff --git a/MapsInMyFolder.Setup/Product.wxs b/MapsInMyFolder.Setup/Product.wxs index adc4c38..37f6aa7 100644 --- a/MapsInMyFolder.Setup/Product.wxs +++ b/MapsInMyFolder.Setup/Product.wxs @@ -5,7 +5,7 @@ - + diff --git a/MapsInMyFolder/CustomOrEditLayersPage.xaml b/MapsInMyFolder/CustomOrEditLayersPage.xaml index 663115f..8de7ea6 100644 --- a/MapsInMyFolder/CustomOrEditLayersPage.xaml +++ b/MapsInMyFolder/CustomOrEditLayersPage.xaml @@ -302,6 +302,7 @@ Grid.ColumnSpan="3" VerticalAlignment="Center" Content="{Binding Source={x:Static commun:Languages.Current}, Path=[editorOpenAreaEditor]}" + ContentStringFormat="{}→ {0}" Foreground="#888989" IsTabStop="True" MouseEnter="ClickableLabel_MouseEnter" @@ -354,6 +355,7 @@ Grid.ColumnSpan="3" VerticalAlignment="Center" Content="{Binding Source={x:Static commun:Languages.Current}, Path=[editorAutoDetectZoom]}" + ContentStringFormat="{}→ {0}" Foreground="#888989" IsTabStop="True" MouseEnter="ClickableLabel_MouseEnter" @@ -569,22 +571,36 @@ +