Menu

[38707f]: / Program.cs  Maximize  Restore  History

Download this file

244 lines (202 with data), 9.0 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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace GitForce
{
static class App
{
#region Application-wide delegates for various callbacks
/// <summary>
/// Multicast delegate for application-wide data refresh. It is initialized with the
/// first app-global refresh handler. Other forms append their own refresh functions
/// in the order they are instantiated.
/// </summary>
public delegate void RefreshDelegate();
public static RefreshDelegate Refresh = ClassRepos.Refresh;
private static bool inRefresh;
/// <summary>
/// Protect Refresh chain with a simple exit mutex, so that the F5 key (update)
/// does not start a re-entrant refresh chain. Although the main GUI app is
/// single-threaded, some panels refresh functions are calling GitRun() which
/// in turn spawns external async process during which time we can end up with
/// multiple threads trying to refresh.
/// </summary>
public static void DoRefresh()
{
if (inRefresh) return;
inRefresh = true;
Refresh();
inRefresh = false;
}
/// <summary>
/// Delegate to main form to print a status message in the status pane.
/// We do it via delegate since it might be called before the main form is created.
/// </summary>
public delegate void PrintStatusMessageHandler(string message, MessageType type);
public static PrintStatusMessageHandler PrintStatusMessage = VoidMessage;
private static void VoidMessage(string m, MessageType type) { }
/// <summary>
/// Delegate to main form to set the busy status.
/// We do it via delegate since it might be called before the main form is created.
/// </summary>
public delegate void SetBusyStatusHandler(bool isBusy);
public static SetBusyStatusHandler StatusBusy = VoidBusy;
private static void VoidBusy(bool f) { }
/// <summary>
/// Delegate to Log form to print a message in the log window.
/// We do it via delegate since it might be called before or after log form is valid.
/// </summary>
public delegate void PrintLogMessageHandler(string message, MessageType type);
public static PrintLogMessageHandler PrintLogMessage = VoidMessage;
#endregion
#region Static forms and classes
/// <summary>
/// Static form with log output
/// </summary>
public static FormLog Log;
/// <summary>
/// Static git class helper containing git-execution services
/// </summary>
public static ClassGit Git;
/// <summary>
/// Static class containing diff tool execution helpers
/// </summary>
public static ClassDiff Diff;
/// <summary>
/// Static class containing merge tool helpers
/// </summary>
public static ClassMerge Merge;
/// <summary>
/// Static class of repos containing operations on a set of repositories
/// </summary>
public static ClassRepos Repos;
/// <summary>
/// Static class PuTTY to manage SSL connections on Windows
/// </summary>
public static ClassPutty Putty;
/// <summary>
/// Static class SSH to manage SSL connections on Linux
/// </summary>
public static ClassSSH Ssh;
/// <summary>
/// Static class managing Git HTTPS password helper file
/// </summary>
public static ClassHttpsPasswd HttpsPasswd;
/// <summary>
/// Static class containing custom tools
/// </summary>
public static ClassCustomTools CustomTools;
/// <summary>
/// Static class containing code to check for a new version
/// </summary>
public static ClassVersion Version;
/// <summary>
/// Static main form class
/// </summary>
public static FormMain MainForm;
#endregion
#region Global variables
/// <summary>
/// Store a path to the application executing instance
/// </summary>
public static readonly string AppPath = Application.ExecutablePath;
/// <summary>
/// Define a path to the application data folder
/// </summary>
public static readonly string AppHome = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GitForce");
/// <summary>
/// Define a path to the user profile.
/// </summary>
public static readonly string UserHome = ClassUtils.GetHomePath();
/// <summary>
/// If set to a file name, all log text will be mirrored to that file
/// Command line argument '--log' sets it to application data folder, file 'gitforce.log'
/// </summary>
public static string AppLog;
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Upgrade application settings across the version increment
ClassUtils.UpgradeApplicationSettingsIfNecessary();
// Make sure the application data folder directory exists
Directory.CreateDirectory(AppHome);
// Get and process command line arguments
Arguments commandLine = new Arguments(args);
// If the processing requested program termination,
// return using the error code created by that class
if (ClassCommandLine.Execute(commandLine) == false)
return ClassCommandLine.ReturnCode;
// Check that only one application instance is running
bool mAcquired;
Mutex mAppMutex = new Mutex(true, "gitforce", out mAcquired);
if (!mAcquired && Properties.Settings.Default.WarnMultipleInstances)
{
if (MessageBox.Show("GitForce is already running.\n\nDo you want to open a new instance?", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
return -1;
}
// Check if the application has been run as Admin/root
if (Properties.Settings.Default.WarnIfAdmin && ClassUtils.IsAdmin())
{
if (MessageBox.Show("GitForce has been run with elevated privileges which is not a recomended way to run it.\n\nDo you still want to continue?", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No)
return -1;
}
// Initialize logging and git execute support
Log = new FormLog();
Log.ShowWindow(Properties.Settings.Default.ShowLogWindow);
Git = new ClassGit();
// Before we can start, we need to have a functional git executable);
if (Git.Initialize())
{
// Initialize external diff program
Diff = new ClassDiff();
if (Diff.Initialize())
{
Merge = new ClassMerge();
// Initialize external Merge program
if (Merge.Initialize())
{
// Add known text editors
Settings.Panels.ControlViewEdit.AddKnownEditors();
if (ClassUtils.IsMono())
Ssh = new ClassSSH(); // Instantiate SSH support only on Linux (Mono)
else
Putty = new ClassPutty(); // Instantiate PuTTY support only on Windows
HttpsPasswd = new ClassHttpsPasswd();
Repos = new ClassRepos();
Version = new ClassVersion();
MainForm = new FormMain();
MainForm.Show();
if (MainForm.Initialize(ClassCommandLine.initRepo)) // Load repos, custom tools etc.
{
DoRefresh();
Application.Run(MainForm);
Properties.Settings.Default.Save();
GC.KeepAlive(mAppMutex);
return 0;
}
}
}
}
return -1;
}
}
public enum MessageType
{
General,
Command,
Output,
Error,
Debug,
NewVersion,
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.