2024-03-17 18:37:06 -07:00
|
|
|
using System;
|
2024-07-02 07:54:26 -07:00
|
|
|
using System.Collections.Generic;
|
2024-03-17 18:37:06 -07:00
|
|
|
using System.IO;
|
2024-03-26 07:11:06 -07:00
|
|
|
using System.Net.Http;
|
2024-03-17 18:37:06 -07:00
|
|
|
using System.Reflection;
|
|
|
|
using System.Text;
|
2024-03-26 07:11:06 -07:00
|
|
|
using System.Text.Json;
|
|
|
|
using System.Threading.Tasks;
|
2024-05-10 20:31:14 -07:00
|
|
|
using System.Windows.Input;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
|
using Avalonia.Data.Core.Plugins;
|
|
|
|
using Avalonia.Markup.Xaml;
|
|
|
|
using Avalonia.Media;
|
2024-03-04 23:53:38 -08:00
|
|
|
using Avalonia.Media.Fonts;
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia.Styling;
|
2024-03-26 07:11:06 -07:00
|
|
|
using Avalonia.Threading;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
namespace SourceGit
|
|
|
|
{
|
2024-05-10 20:31:14 -07:00
|
|
|
public class SimpleCommand : ICommand
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-05-10 20:31:14 -07:00
|
|
|
public event EventHandler CanExecuteChanged
|
|
|
|
{
|
|
|
|
add { }
|
|
|
|
remove { }
|
|
|
|
}
|
|
|
|
|
|
|
|
public SimpleCommand(Action action)
|
|
|
|
{
|
|
|
|
_action = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CanExecute(object parameter) => _action != null;
|
|
|
|
public void Execute(object parameter) => _action?.Invoke();
|
|
|
|
|
|
|
|
private Action _action = null;
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-05-10 20:31:14 -07:00
|
|
|
public partial class App : Application
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
[STAThread]
|
2024-03-17 18:37:06 -07:00
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2024-08-12 06:29:18 -07:00
|
|
|
Native.OS.SetupDataDir();
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
|
2024-07-11 20:09:46 -07:00
|
|
|
{
|
|
|
|
LogException(e.ExceptionObject as Exception);
|
|
|
|
};
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
TaskScheduler.UnobservedTaskException += (_, e) =>
|
2024-07-11 20:09:46 -07:00
|
|
|
{
|
|
|
|
LogException(e.Exception);
|
|
|
|
e.SetObserved();
|
|
|
|
};
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
try
|
|
|
|
{
|
2024-07-08 19:16:15 -07:00
|
|
|
if (TryLaunchedAsRebaseTodoEditor(args, out int exitTodo))
|
|
|
|
Environment.Exit(exitTodo);
|
|
|
|
else if (TryLaunchedAsRebaseMessageEditor(args, out int exitMessage))
|
|
|
|
Environment.Exit(exitMessage);
|
2024-06-20 02:02:12 -07:00
|
|
|
else
|
|
|
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2024-07-11 20:09:46 -07:00
|
|
|
LogException(ex);
|
2024-03-17 18:37:06 -07:00
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static AppBuilder BuildAvaloniaApp()
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var builder = AppBuilder.Configure<App>();
|
|
|
|
builder.UsePlatformDetect();
|
2024-03-07 20:22:22 -08:00
|
|
|
builder.LogToTrace();
|
2024-03-17 18:37:06 -07:00
|
|
|
builder.ConfigureFonts(manager =>
|
|
|
|
{
|
2024-03-04 23:53:38 -08:00
|
|
|
var monospace = new EmbeddedFontCollection(
|
|
|
|
new Uri("fonts:SourceGit", UriKind.Absolute),
|
|
|
|
new Uri("avares://SourceGit/Resources/Fonts", UriKind.Absolute));
|
|
|
|
manager.AddFontCollection(monospace);
|
|
|
|
});
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-14 03:23:36 -07:00
|
|
|
Native.OS.SetupApp(builder);
|
2024-02-05 23:08:37 -08:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2024-05-10 20:31:14 -07:00
|
|
|
public static readonly SimpleCommand OpenPreferenceCommand = new SimpleCommand(() =>
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
var toplevel = GetTopLevel() as Window;
|
|
|
|
if (toplevel == null)
|
|
|
|
return;
|
2024-07-22 22:58:57 -07:00
|
|
|
|
2024-05-10 20:31:14 -07:00
|
|
|
var dialog = new Views.Preference();
|
2024-07-14 09:30:31 -07:00
|
|
|
dialog.ShowDialog(toplevel);
|
2024-05-10 20:31:14 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
public static readonly SimpleCommand OpenHotkeysCommand = new SimpleCommand(() =>
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
var toplevel = GetTopLevel() as Window;
|
|
|
|
if (toplevel == null)
|
|
|
|
return;
|
2024-07-22 22:58:57 -07:00
|
|
|
|
2024-05-10 20:31:14 -07:00
|
|
|
var dialog = new Views.Hotkeys();
|
2024-07-14 09:30:31 -07:00
|
|
|
dialog.ShowDialog(toplevel);
|
2024-05-10 20:31:14 -07:00
|
|
|
});
|
|
|
|
|
2024-08-14 20:47:04 -07:00
|
|
|
public static readonly SimpleCommand OpenAppDataDirCommand = new SimpleCommand(() =>
|
|
|
|
{
|
|
|
|
Native.OS.OpenInFileManager(Native.OS.DataDir);
|
|
|
|
});
|
|
|
|
|
2024-05-10 20:31:14 -07:00
|
|
|
public static readonly SimpleCommand OpenAboutCommand = new SimpleCommand(() =>
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
var toplevel = GetTopLevel() as Window;
|
|
|
|
if (toplevel == null)
|
|
|
|
return;
|
2024-07-22 22:58:57 -07:00
|
|
|
|
2024-05-10 20:31:14 -07:00
|
|
|
var dialog = new Views.About();
|
2024-07-14 09:30:31 -07:00
|
|
|
dialog.ShowDialog(toplevel);
|
2024-05-10 20:31:14 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
public static readonly SimpleCommand CheckForUpdateCommand = new SimpleCommand(() =>
|
|
|
|
{
|
|
|
|
Check4Update(true);
|
|
|
|
});
|
|
|
|
|
2024-07-14 18:54:46 -07:00
|
|
|
public static readonly SimpleCommand QuitCommand = new SimpleCommand(() => Quit(0));
|
2024-05-10 20:31:14 -07:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static void RaiseException(string context, string message)
|
|
|
|
{
|
2024-06-26 05:56:29 -07:00
|
|
|
if (Current is App app && app._launcher != null)
|
|
|
|
app._launcher.DispatchNotification(context, message, true);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static void SendNotification(string context, string message)
|
|
|
|
{
|
2024-06-26 05:56:29 -07:00
|
|
|
if (Current is App app && app._launcher != null)
|
|
|
|
app._launcher.DispatchNotification(context, message, false);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static void SetLocale(string localeKey)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var app = Current as App;
|
2024-07-14 09:30:31 -07:00
|
|
|
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
|
2024-04-06 03:06:32 -07:00
|
|
|
if (targetLocale == null || targetLocale == app._activeLocale)
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (app._activeLocale != null)
|
2024-02-05 23:08:37 -08:00
|
|
|
app.Resources.MergedDictionaries.Remove(app._activeLocale);
|
|
|
|
|
2024-04-06 03:06:32 -07:00
|
|
|
app.Resources.MergedDictionaries.Add(targetLocale);
|
|
|
|
app._activeLocale = targetLocale;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-07-08 01:21:57 -07:00
|
|
|
public static void SetTheme(string theme, string themeOverridesFile)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-06-05 03:23:28 -07:00
|
|
|
var app = Current as App;
|
2024-07-14 09:30:31 -07:00
|
|
|
if (app == null)
|
|
|
|
return;
|
2024-06-05 03:23:28 -07:00
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
|
2024-06-05 03:23:28 -07:00
|
|
|
app.RequestedThemeVariant = ThemeVariant.Light;
|
2024-03-17 18:37:06 -07:00
|
|
|
else if (theme.Equals("Dark", StringComparison.OrdinalIgnoreCase))
|
2024-06-05 03:23:28 -07:00
|
|
|
app.RequestedThemeVariant = ThemeVariant.Dark;
|
2024-03-17 18:37:06 -07:00
|
|
|
else
|
2024-06-05 03:23:28 -07:00
|
|
|
app.RequestedThemeVariant = ThemeVariant.Default;
|
|
|
|
|
2024-07-08 01:21:57 -07:00
|
|
|
if (app._themeOverrides != null)
|
2024-06-05 03:23:28 -07:00
|
|
|
{
|
2024-07-08 01:21:57 -07:00
|
|
|
app.Resources.MergedDictionaries.Remove(app._themeOverrides);
|
|
|
|
app._themeOverrides = null;
|
2024-06-05 03:23:28 -07:00
|
|
|
}
|
|
|
|
|
2024-07-08 01:21:57 -07:00
|
|
|
if (!string.IsNullOrEmpty(themeOverridesFile) && File.Exists(themeOverridesFile))
|
2024-06-05 03:23:28 -07:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var resDic = new ResourceDictionary();
|
2024-07-08 01:21:57 -07:00
|
|
|
var overrides = JsonSerializer.Deserialize(File.ReadAllText(themeOverridesFile), JsonCodeGen.Default.ThemeOverrides);
|
|
|
|
foreach (var kv in overrides.BasicColors)
|
2024-07-02 09:17:18 -07:00
|
|
|
{
|
|
|
|
if (kv.Key.Equals("SystemAccentColor", StringComparison.Ordinal))
|
2024-07-08 01:45:51 -07:00
|
|
|
resDic["SystemAccentColor"] = kv.Value;
|
2024-07-02 09:17:18 -07:00
|
|
|
else
|
2024-07-08 01:45:51 -07:00
|
|
|
resDic[$"Color.{kv.Key}"] = kv.Value;
|
2024-07-02 09:17:18 -07:00
|
|
|
}
|
2024-07-02 07:54:26 -07:00
|
|
|
|
2024-07-08 01:21:57 -07:00
|
|
|
if (overrides.GraphColors.Count > 0)
|
2024-07-08 01:45:51 -07:00
|
|
|
Models.CommitGraph.SetPens(overrides.GraphColors, overrides.GraphPenThickness);
|
2024-07-08 01:21:57 -07:00
|
|
|
else
|
|
|
|
Models.CommitGraph.SetDefaultPens(overrides.GraphPenThickness);
|
2024-07-05 05:02:30 -07:00
|
|
|
|
2024-07-17 19:46:39 -07:00
|
|
|
Models.Commit.OpacityForNotMerged = overrides.OpacityForNotMergedCommits;
|
|
|
|
|
2024-06-05 03:23:28 -07:00
|
|
|
app.Resources.MergedDictionaries.Add(resDic);
|
2024-07-08 01:21:57 -07:00
|
|
|
app._themeOverrides = resDic;
|
2024-06-06 00:31:02 -07:00
|
|
|
}
|
2024-06-05 03:23:28 -07:00
|
|
|
catch
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
// ignore
|
2024-06-05 03:23:28 -07:00
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-07-08 01:21:57 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Models.CommitGraph.SetDefaultPens();
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static async void CopyText(string data)
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-08-02 00:40:00 -07:00
|
|
|
if (desktop.MainWindow?.Clipboard is { } clipboard)
|
|
|
|
await clipboard.SetTextAsync(data);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-30 20:57:13 -07:00
|
|
|
public static async Task<string> GetClipboardTextAsync()
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
2024-06-30 20:57:13 -07:00
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
if (desktop.MainWindow?.Clipboard is { } clipboard)
|
2024-06-30 20:57:13 -07:00
|
|
|
{
|
|
|
|
return await clipboard.GetTextAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return default;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static string Text(string key, params object[] args)
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
var fmt = Current?.FindResource($"Text.{key}") as string;
|
2024-03-31 01:54:29 -07:00
|
|
|
if (string.IsNullOrWhiteSpace(fmt))
|
|
|
|
return $"Text.{key}";
|
2024-06-17 19:19:55 -07:00
|
|
|
|
|
|
|
if (args == null || args.Length == 0)
|
|
|
|
return fmt;
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
return string.Format(fmt, args);
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
|
|
|
|
{
|
2024-02-27 02:26:05 -08:00
|
|
|
var icon = new Avalonia.Controls.Shapes.Path();
|
|
|
|
icon.Width = 12;
|
|
|
|
icon.Height = 12;
|
|
|
|
icon.Stretch = Stretch.Uniform;
|
2024-07-14 09:30:31 -07:00
|
|
|
|
|
|
|
var geo = Current?.FindResource(key) as StreamGeometry;
|
|
|
|
if (geo != null)
|
|
|
|
icon.Data = geo;
|
2024-07-22 22:58:57 -07:00
|
|
|
|
2024-02-27 02:26:05 -08:00
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public static TopLevel GetTopLevel()
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
return desktop.MainWindow;
|
|
|
|
}
|
2024-07-22 22:58:57 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-03-26 07:11:06 -07:00
|
|
|
public static void Check4Update(bool manually = false)
|
|
|
|
{
|
|
|
|
Task.Run(async () =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Fetch lastest release information.
|
2024-04-25 18:40:02 -07:00
|
|
|
var client = new HttpClient() { Timeout = TimeSpan.FromSeconds(5) };
|
2024-04-15 18:23:54 -07:00
|
|
|
var data = await client.GetStringAsync("https://sourcegit-scm.github.io/data/version.json");
|
2024-03-26 07:11:06 -07:00
|
|
|
|
|
|
|
// Parse json into Models.Version.
|
|
|
|
var ver = JsonSerializer.Deserialize(data, JsonCodeGen.Default.Version);
|
2024-03-31 01:54:29 -07:00
|
|
|
if (ver == null)
|
|
|
|
return;
|
2024-03-26 07:11:06 -07:00
|
|
|
|
|
|
|
// Check if already up-to-date.
|
|
|
|
if (!ver.IsNewVersion)
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
if (manually)
|
|
|
|
ShowSelfUpdateResult(new Models.AlreadyUpToDate());
|
2024-03-26 07:11:06 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not check ignored tag if this is called manually.
|
|
|
|
if (!manually)
|
|
|
|
{
|
|
|
|
var pref = ViewModels.Preference.Instance;
|
2024-03-31 01:54:29 -07:00
|
|
|
if (ver.TagName == pref.IgnoreUpdateTag)
|
|
|
|
return;
|
2024-03-26 07:11:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ShowSelfUpdateResult(ver);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
if (manually)
|
|
|
|
ShowSelfUpdateResult(e);
|
2024-03-26 07:11:06 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-23 23:32:27 -07:00
|
|
|
public static ViewModels.Launcher GetLauncer()
|
|
|
|
{
|
|
|
|
return Current is App app ? app._launcher : null;
|
|
|
|
}
|
|
|
|
|
2024-06-30 20:57:13 -07:00
|
|
|
public static ViewModels.Repository FindOpenedRepository(string repoPath)
|
|
|
|
{
|
|
|
|
if (Current is App app && app._launcher != null)
|
|
|
|
{
|
|
|
|
foreach (var page in app._launcher.Pages)
|
|
|
|
{
|
|
|
|
var id = page.Node.Id.Replace("\\", "/");
|
|
|
|
if (id == repoPath && page.Data is ViewModels.Repository repo)
|
|
|
|
return repo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2024-07-14 18:54:46 -07:00
|
|
|
public static void Quit(int exitCode)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
desktop.MainWindow?.Close();
|
2024-07-14 18:54:46 -07:00
|
|
|
desktop.Shutdown(exitCode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Environment.Exit(exitCode);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public override void Initialize()
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
|
|
|
2024-03-21 05:55:08 -07:00
|
|
|
var pref = ViewModels.Preference.Instance;
|
|
|
|
|
|
|
|
SetLocale(pref.Locale);
|
2024-07-08 01:21:57 -07:00
|
|
|
SetTheme(pref.Theme, pref.ThemeOverrides);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
|
|
{
|
|
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
BindingPlugins.DataValidators.RemoveAt(0);
|
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
if (TryLaunchedAsCoreEditor(desktop))
|
|
|
|
return;
|
2024-07-08 07:07:00 -07:00
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
if (TryLaunchedAsAskpass(desktop))
|
|
|
|
return;
|
2024-07-08 07:07:00 -07:00
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
TryLaunchedAsNormal(desktop);
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-11 20:09:46 -07:00
|
|
|
private static void LogException(Exception ex)
|
|
|
|
{
|
2024-07-14 00:55:15 -07:00
|
|
|
if (ex == null)
|
|
|
|
return;
|
2024-07-11 20:09:46 -07:00
|
|
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
builder.Append($"Crash::: {ex.GetType().FullName}: {ex.Message}\n\n");
|
|
|
|
builder.Append("----------------------------\n");
|
|
|
|
builder.Append($"Version: {Assembly.GetExecutingAssembly().GetName().Version}\n");
|
|
|
|
builder.Append($"OS: {Environment.OSVersion.ToString()}\n");
|
|
|
|
builder.Append($"Framework: {AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}\n");
|
|
|
|
builder.Append($"Source: {ex.Source}\n");
|
|
|
|
builder.Append($"---------------------------\n\n");
|
|
|
|
builder.Append(ex.StackTrace);
|
|
|
|
while (ex.InnerException != null)
|
|
|
|
{
|
|
|
|
ex = ex.InnerException;
|
|
|
|
builder.Append($"\n\nInnerException::: {ex.GetType().FullName}: {ex.Message}\n");
|
|
|
|
builder.Append(ex.StackTrace);
|
|
|
|
}
|
|
|
|
|
|
|
|
var time = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
|
|
|
|
var file = Path.Combine(Native.OS.DataDir, $"crash_{time}.log");
|
|
|
|
File.WriteAllText(file, builder.ToString());
|
|
|
|
}
|
|
|
|
|
2024-03-26 07:11:06 -07:00
|
|
|
private static void ShowSelfUpdateResult(object data)
|
|
|
|
{
|
|
|
|
Dispatcher.UIThread.Post(() =>
|
|
|
|
{
|
2024-07-14 09:30:31 -07:00
|
|
|
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: not null } desktop)
|
2024-03-26 07:11:06 -07:00
|
|
|
{
|
|
|
|
var dialog = new Views.SelfUpdate()
|
|
|
|
{
|
2024-07-08 19:16:15 -07:00
|
|
|
DataContext = new ViewModels.SelfUpdate() { Data = data }
|
2024-03-26 07:11:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
dialog.Show(desktop.MainWindow);
|
2024-03-28 02:46:03 -07:00
|
|
|
}
|
2024-03-26 07:11:06 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
private static bool TryLaunchedAsRebaseTodoEditor(string[] args, out int exitCode)
|
|
|
|
{
|
|
|
|
exitCode = -1;
|
|
|
|
|
|
|
|
if (args.Length <= 1 || !args[0].Equals("--rebase-todo-editor", StringComparison.Ordinal))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var file = args[1];
|
|
|
|
var filename = Path.GetFileName(file);
|
|
|
|
if (!filename.Equals("git-rebase-todo", StringComparison.OrdinalIgnoreCase))
|
|
|
|
return true;
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
var dirInfo = new DirectoryInfo(Path.GetDirectoryName(file)!);
|
2024-07-08 19:16:15 -07:00
|
|
|
if (!dirInfo.Exists || !dirInfo.Name.Equals("rebase-merge", StringComparison.Ordinal))
|
|
|
|
return true;
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
var jobsFile = Path.Combine(dirInfo.Parent!.FullName, "sourcegit_rebase_jobs.json");
|
2024-07-08 19:16:15 -07:00
|
|
|
if (!File.Exists(jobsFile))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection);
|
|
|
|
var lines = new List<string>();
|
|
|
|
foreach (var job in collection.Jobs)
|
|
|
|
{
|
|
|
|
switch (job.Action)
|
|
|
|
{
|
|
|
|
case Models.InteractiveRebaseAction.Pick:
|
|
|
|
lines.Add($"p {job.SHA}");
|
|
|
|
break;
|
|
|
|
case Models.InteractiveRebaseAction.Edit:
|
|
|
|
lines.Add($"e {job.SHA}");
|
|
|
|
break;
|
|
|
|
case Models.InteractiveRebaseAction.Reword:
|
|
|
|
lines.Add($"r {job.SHA}");
|
|
|
|
break;
|
|
|
|
case Models.InteractiveRebaseAction.Squash:
|
|
|
|
lines.Add($"s {job.SHA}");
|
|
|
|
break;
|
|
|
|
case Models.InteractiveRebaseAction.Fixup:
|
|
|
|
lines.Add($"f {job.SHA}");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lines.Add($"d {job.SHA}");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
File.WriteAllLines(file, lines);
|
|
|
|
|
|
|
|
exitCode = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool TryLaunchedAsRebaseMessageEditor(string[] args, out int exitCode)
|
2024-07-08 07:07:00 -07:00
|
|
|
{
|
2024-07-08 19:16:15 -07:00
|
|
|
exitCode = -1;
|
2024-07-08 07:07:00 -07:00
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
if (args.Length <= 1 || !args[0].Equals("--rebase-message-editor", StringComparison.Ordinal))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var file = args[1];
|
|
|
|
var filename = Path.GetFileName(file);
|
|
|
|
if (!filename.Equals("COMMIT_EDITMSG", StringComparison.OrdinalIgnoreCase))
|
|
|
|
return true;
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
var jobsFile = Path.Combine(Path.GetDirectoryName(file)!, "sourcegit_rebase_jobs.json");
|
2024-07-08 19:16:15 -07:00
|
|
|
if (!File.Exists(jobsFile))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection);
|
2024-07-14 09:30:31 -07:00
|
|
|
var doneFile = Path.Combine(Path.GetDirectoryName(file)!, "rebase-merge", "done");
|
2024-07-08 19:16:15 -07:00
|
|
|
if (!File.Exists(doneFile))
|
|
|
|
return true;
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
var done = File.ReadAllText(doneFile).Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
2024-07-08 19:16:15 -07:00
|
|
|
if (done.Length > collection.Jobs.Count)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var job = collection.Jobs[done.Length - 1];
|
|
|
|
File.WriteAllText(file, job.Message);
|
|
|
|
|
|
|
|
exitCode = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool TryLaunchedAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
|
{
|
|
|
|
var args = desktop.Args;
|
2024-07-14 09:30:31 -07:00
|
|
|
if (args == null || args.Length <= 1 || !args[0].Equals("--core-editor", StringComparison.Ordinal))
|
2024-07-08 19:16:15 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
var file = args[1];
|
|
|
|
if (!File.Exists(file))
|
2024-07-14 18:54:46 -07:00
|
|
|
desktop.Shutdown(-1);
|
|
|
|
else
|
|
|
|
desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file);
|
2024-07-08 19:16:15 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool TryLaunchedAsAskpass(IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
|
{
|
|
|
|
var args = desktop.Args;
|
2024-07-22 22:48:52 -07:00
|
|
|
if (args == null || args.Length != 1)
|
2024-07-08 07:07:00 -07:00
|
|
|
return false;
|
2024-07-09 21:11:51 -07:00
|
|
|
|
2024-07-22 22:48:52 -07:00
|
|
|
var param = args[0];
|
|
|
|
if (!param.StartsWith("enter passphrase", StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
!param.Contains(" password", StringComparison.OrdinalIgnoreCase))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
desktop.MainWindow = new Views.Askpass(param);
|
2024-07-08 19:16:15 -07:00
|
|
|
return true;
|
|
|
|
}
|
2024-07-08 07:07:00 -07:00
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
private void TryLaunchedAsNormal(IClassicDesktopStyleApplicationLifetime desktop)
|
|
|
|
{
|
|
|
|
Native.OS.SetupEnternalTools();
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
string startupRepo = null;
|
|
|
|
if (desktop.Args != null && desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0]))
|
|
|
|
startupRepo = desktop.Args[0];
|
|
|
|
|
2024-07-08 19:16:15 -07:00
|
|
|
_launcher = new ViewModels.Launcher(startupRepo);
|
|
|
|
desktop.MainWindow = new Views.Launcher() { DataContext = _launcher };
|
|
|
|
|
|
|
|
var pref = ViewModels.Preference.Instance;
|
2024-07-22 00:34:31 -07:00
|
|
|
if (pref.ShouldCheck4UpdateOnStartup())
|
2024-07-08 19:16:15 -07:00
|
|
|
{
|
|
|
|
pref.Save();
|
|
|
|
Check4Update();
|
|
|
|
}
|
2024-07-08 07:07:00 -07:00
|
|
|
}
|
|
|
|
|
2024-06-26 05:56:29 -07:00
|
|
|
private ViewModels.Launcher _launcher = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
private ResourceDictionary _activeLocale = null;
|
2024-07-08 01:21:57 -07:00
|
|
|
private ResourceDictionary _themeOverrides = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|