Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (76 loc) · 4.07 KB
/
Copy pathProgram.cs
File metadata and controls
81 lines (76 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// WindowGrid – Fenster beim Ziehen per Raster anordnen
// Copyright (C) 2026 Günther Schoder · https://www.westmc002.de
// Lizenz: GNU General Public License v3.0 oder später (siehe LICENSE)
// SPDX-License-Identifier: GPL-3.0-or-later
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowGrid
{
internal static class Program
{
/// <summary>Versuchskennung aus „--nach-update <Kennung>“ (ab 1.68), sonst null.</summary>
internal static string UpdateAttempt;
[STAThread]
private static int Main(string[] args)
{
// Screenshots für GitHub mit Beispieldaten: WindowGrid.exe --screenshots [Zielordner]
int shot = Array.FindIndex(args, a => string.Equals(a, "--screenshots", StringComparison.OrdinalIgnoreCase));
if (shot >= 0)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string dir = shot + 1 < args.Length ? args[shot + 1] : System.IO.Path.Combine(AppInfo.ExeDirectory, "Screenshots");
return Demo.RunScreenshots(dir) ? 0 : 1;
}
bool created;
using (Mutex mutex = new Mutex(true, "WindowGrid_Modern_SingleInstance", out created))
{
// Neustart mit Adminrechten: warten, bis sich die alte Instanz beendet hat
bool afterUpdate = Array.Exists(args, a => string.Equals(a, "--nach-update", StringComparison.OrdinalIgnoreCase));
// ab 1.68 folgt die Versuchskennung (32 Hex-Zeichen): nur das Ergebnis genau dieses Versuchs lesen
int at = Array.FindIndex(args, a => string.Equals(a, "--nach-update", StringComparison.OrdinalIgnoreCase));
if (at >= 0 && at + 1 < args.Length && Updater.IsAttemptId(args[at + 1])) UpdateAttempt = args[at + 1];
bool restart = afterUpdate || Array.Exists(args, a => string.Equals(a, "/neustart", StringComparison.OrdinalIgnoreCase));
if (!created && restart)
{
try { created = mutex.WaitOne(10000); }
catch (AbandonedMutexException) { created = true; }
}
if (!created)
{
// Läuft schon – dort die Einstellungen öffnen
try
{
EventWaitHandle ev = EventWaitHandle.OpenExisting(TrayContext.ShowSettingsEventName);
ev.Set();
ev.Dispose();
}
catch { }
return 0;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Falls WindowGrid unerwartet endet: Windows-Andocken wieder einschalten
AppDomain.CurrentDomain.ProcessExit += delegate { GridEngine.RestoreSnap(); };
AppDomain.CurrentDomain.UnhandledException += delegate (object s, UnhandledExceptionEventArgs e)
{
GridEngine.RestoreSnap();
Log.Write("Unerwarteter Fehler", e.ExceptionObject as Exception);
};
Application.ThreadException += delegate (object s, ThreadExceptionEventArgs e)
{
GridEngine.RestoreSnap();
Log.Write("Unerwarteter Fehler", e.Exception);
MessageBox.Show("Unerwarteter Fehler:\n\n" + e.Exception.Message, "WindowGrid",
MessageBoxButtons.OK, MessageBoxIcon.Error);
};
// /tray: nach dem Update nur im Infobereich starten (Fenster war vorher zu)
bool tray = Array.Exists(args, a => string.Equals(a, "/tray", StringComparison.OrdinalIgnoreCase));
Application.Run(new TrayContext(afterUpdate, tray));
GC.KeepAlive(mutex);
}
return 0;
}
}
}