Remove conversion for utf8 encoded strings on macOS - with proper settings on git command things are already and would get worse if default encoding is ASCII (which seems to be the case for current VisualStudio 2019)

This commit is contained in:
Markus Stoll 2021-02-14 19:27:22 +01:00
parent 613625c5bf
commit 741ea0612a
4 changed files with 37 additions and 15 deletions

View file

@ -21,13 +21,20 @@ using Sparkles;
namespace SparkleShare { namespace SparkleShare {
public class BubblesController { public class BubblesController {
private bool fix_utf_encoding;
public event ShowBubbleEventHandler ShowBubbleEvent = delegate { }; public event ShowBubbleEventHandler ShowBubbleEvent = delegate { };
public delegate void ShowBubbleEventHandler (string title, string subtext, string image_path); public delegate void ShowBubbleEventHandler (string title, string subtext, string image_path);
public BubblesController () public BubblesController () : this(true)
{ {
}
public BubblesController (bool fix_utf_encoding)
{
this.fix_utf_encoding = fix_utf_encoding;
SparkleShare.Controller.AlertNotificationRaised += delegate (string title, string message) { SparkleShare.Controller.AlertNotificationRaised += delegate (string title, string message) {
ShowBubble (title, message, null); ShowBubble (title, message, null);
}; };
@ -40,10 +47,13 @@ namespace SparkleShare {
public void ShowBubble (string title, string subtext, string image_path) public void ShowBubble (string title, string subtext, string image_path)
{ {
byte [] title_bytes = Encoding.Default.GetBytes (title); if(fix_utf_encoding)
byte [] subtext_bytes = Encoding.Default.GetBytes (subtext); {
title = Encoding.UTF8.GetString (title_bytes); byte [] title_bytes = Encoding.Default.GetBytes (title);
subtext = Encoding.UTF8.GetString (subtext_bytes); byte [] subtext_bytes = Encoding.Default.GetBytes (subtext);
title = Encoding.UTF8.GetString (title_bytes);
subtext = Encoding.UTF8.GetString (subtext_bytes);
}
ShowBubbleEvent (title, subtext, image_path); ShowBubbleEvent (title, subtext, image_path);
} }

View file

@ -53,7 +53,7 @@ namespace SparkleShare {
private string selected_folder; private string selected_folder;
private RevisionInfo restore_revision_info; private RevisionInfo restore_revision_info;
private bool history_view_active; private bool history_view_active;
private bool fix_utf_encoding;
public bool WindowIsOpen { get; private set; } public bool WindowIsOpen { get; private set; }
@ -144,8 +144,14 @@ namespace SparkleShare {
} }
public EventLogController () public EventLogController () : this (true)
{ {
}
public EventLogController (bool fix_utf_encoding)
{
this.fix_utf_encoding = fix_utf_encoding;
SparkleShare.Controller.ShowEventLogWindowEvent += delegate { SparkleShare.Controller.ShowEventLogWindowEvent += delegate {
if (!WindowIsOpen) { if (!WindowIsOpen) {
ContentLoadingEvent (); ContentLoadingEvent ();
@ -257,8 +263,11 @@ namespace SparkleShare {
string folder = href.Replace ("history://", "").Split ("/".ToCharArray ()) [0]; string folder = href.Replace ("history://", "").Split ("/".ToCharArray ()) [0];
string file_path = href.Replace ("history://" + folder + "/", ""); string file_path = href.Replace ("history://" + folder + "/", "");
byte [] file_path_bytes = Encoding.Default.GetBytes (file_path); if(fix_utf_encoding)
file_path = Encoding.UTF8.GetString (file_path_bytes); {
byte [] file_path_bytes = Encoding.Default.GetBytes (file_path);
file_path = Encoding.UTF8.GetString (file_path_bytes);
}
file_path = Uri.UnescapeDataString (file_path); file_path = Uri.UnescapeDataString (file_path);
@ -536,10 +545,13 @@ namespace SparkleShare {
private string FormatBreadCrumbs (string path_root, string path) private string FormatBreadCrumbs (string path_root, string path)
{ {
byte [] path_root_bytes = Encoding.Default.GetBytes (path_root); if(fix_utf_encoding)
byte [] path_bytes = Encoding.Default.GetBytes (path); {
path_root = Encoding.UTF8.GetString (path_root_bytes); byte [] path_root_bytes = Encoding.Default.GetBytes (path_root);
path = Encoding.UTF8.GetString (path_bytes); byte [] path_bytes = Encoding.Default.GetBytes (path);
path_root = Encoding.UTF8.GetString (path_root_bytes);
path = Encoding.UTF8.GetString (path_bytes);
}
path_root = path_root.Replace ("/", Path.DirectorySeparatorChar.ToString ()); path_root = path_root.Replace ("/", Path.DirectorySeparatorChar.ToString ());
path = path.Replace ("/", Path.DirectorySeparatorChar.ToString ()); path = path.Replace ("/", Path.DirectorySeparatorChar.ToString ());

2
SparkleShare/Mac/UserInterface/Bubbles.cs Executable file → Normal file
View file

@ -22,7 +22,7 @@ namespace SparkleShare {
public class Bubbles : NSObject { public class Bubbles : NSObject {
public BubblesController Controller = new BubblesController (); public BubblesController Controller = new BubblesController (false);
public Bubbles () public Bubbles ()

View file

@ -27,7 +27,7 @@ namespace SparkleShare {
public class EventLog : NSWindow { public class EventLog : NSWindow {
public EventLogController Controller = new EventLogController (); public EventLogController Controller = new EventLogController (false);
public float TitlebarHeight; public float TitlebarHeight;
WebView web_view; WebView web_view;