Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SioGabx committed Sep 3, 2023
1 parent 2557c77 commit c89a04e
Show file tree
Hide file tree
Showing 18 changed files with 2,042 additions and 304 deletions.
49 changes: 46 additions & 3 deletions MapsInMyFolder.Common/Collectif.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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()
{
Expand All @@ -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<Diff> diffs = dmp.diff_main(texteBase, texteModif);
SolidColorBrush BackgroundGreen = HexValueToSolidColorBrush("#6b803f");
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 18 additions & 15 deletions MapsInMyFolder.Common/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -174,7 +174,7 @@ static public SQLiteDataReader ExecuteExecuteReaderSQLCommand(string querry)
}
}
} while (HasError);
return null;
return (null, null);
}

static public int ExecuteScalarSQLCommand(string querry)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;");
Expand All @@ -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;
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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<string, string> TableCollumsNames = new Dictionary<string, string>();
using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info(LAYERS)"))
using (SQLiteDataReader LayersTables = ExecuteExecuteReaderSQLCommand($"PRAGMA table_info(LAYERS)").Reader)
{
while (LayersTables.Read())
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -742,7 +744,8 @@ public static void Export(string FilePath)
{
IntLayerVersion = 0;
}
ValuesList["VERSION"] = IntLayerVersion++.ToString();

ValuesList["VERSION"] = (IntLayerVersion + 1).ToString();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions MapsInMyFolder.Common/Javascript.Functions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
Expand Down Expand Up @@ -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<TextBox>(() =>
{
var (textBox, dialog) = Message.SetInputBoxDialog(texte, caption);
var (textBox, dialog) = Message.SetInputBoxDialog(texte, string.Empty, caption);

void Dialog_Closed(object sender, EventArgs e)
{
Expand Down
1 change: 0 additions & 1 deletion MapsInMyFolder.Common/Javascript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Esprima.Ast;
using Jint;
using Jint.Native;
using MapsInMyFolder.VectorTileRenderer;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand Down
5 changes: 3 additions & 2 deletions MapsInMyFolder.Common/MessageContentDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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();
Expand Down
41 changes: 34 additions & 7 deletions MapsInMyFolder.Common/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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 });
}

}
}
2 changes: 1 addition & 1 deletion MapsInMyFolder.Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?include $(sys.CURRENTDIR)Files.wxi ?>

<!--DONT FORGET TO CHANGE THE VERSION NUMER HERE AND IN MAPSINMYFOLDER.CSPROJ-->
<Product Id="*" Name="MapsInMyFolder" Language="1033" Version="0.5.0" Manufacturer="SioGabx" UpgradeCode="091b4d98-0e03-441f-8e40-acb9706db235">
<Product Id="*" Name="MapsInMyFolder" Language="1033" Version="0.5.1" Manufacturer="SioGabx" UpgradeCode="091b4d98-0e03-441f-8e40-acb9706db235">
<Package InstallerVersion="200" Compressed="yes" InstallPrivileges="elevated" AdminImage="yes" Manufacturer="SioGabx" Description="This program provides the functionality to install MapsInMyFolder." Comments="This program provides the functionality to install MapsInMyFolder. See https://github.com/SioGabx/MapsInMyFolder" /><!--InstallScope="perUser"-->
<Media Id="1" Cabinet="MyCabFile.cab" EmbedCab="yes"/>

Expand Down
20 changes: 18 additions & 2 deletions MapsInMyFolder/CustomOrEditLayersPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -569,22 +571,36 @@

<Grid Margin="0,30,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition />
</Grid.RowDefinitions>
<Label
x:Name="ResetInfoLayerClikableLabel"
x:Name="ImportExportInfoLayerClikableLabel"
Grid.Row="0"
Content="{Binding Source={x:Static commun:Languages.Current}, Path=[editorImportExportLayerProperty]}"
ContentStringFormat="{}→ {0}"
Foreground="#888989"
MouseEnter="ClickableLabel_MouseEnter"
MouseLeave="ClickableLabel_MouseLeave"
MouseUp="ImportExportInfoLayerClikableLabel_MouseUp" />


<Label
x:Name="ResetInfoLayerClikableLabel"
Grid.Row="1"
Content="{Binding Source={x:Static commun:Languages.Current}, Path=[editorResetLayerProperty]}"
ContentStringFormat="{}→ {0}"
Foreground="#888989"
MouseEnter="ClickableLabel_MouseEnter"
MouseLeave="ClickableLabel_MouseLeave"
MouseUp="ResetInfoLayerClikableLabel_MouseUp" />
<Label
x:Name="DeleteLayerClikableLabel"
Grid.Row="1"
Grid.Row="2"
Content="{Binding Source={x:Static commun:Languages.Current}, Path=[editorDeleteLayer]}"
ContentStringFormat="{}→ {0}"
Foreground="#888989"
MouseEnter="ClickableLabel_MouseEnter"
MouseLeave="ClickableLabel_MouseLeave"
Expand Down
Loading

0 comments on commit c89a04e

Please sign in to comment.