This repository was archived by the owner on Apr 10, 2022. It is now read-only.
forked from phobos2077/sfall_script_editor
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
79 lines (71 loc) · 3.12 KB
/
Copy pathProgram.cs
File metadata and controls
79 lines (71 loc) · 3.12 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
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace ScriptEditor
{
static class Program
{
static Mutex mutex = new Mutex(true, "SFALL_SCRIPT_EDITOR_4");
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// reset working folder to EXE directory (to resolve possible issues in parse_main)
Directory.SetCurrentDirectory(Application.StartupPath);
if (args.Length > 0 && mutex.WaitOne(TimeSpan.Zero, true)
&& Path.GetExtension(args[0]).ToLowerInvariant() == ".msg") {
mutex.Close();
// run only Messages editor
printLog("Run only message editor...");
Settings.Load();
MessageEditor me = new MessageEditor(args[0].ToString());
Application.Run(me);
} else {
// check if another instance is already running
if (mutex.WaitOne(TimeSpan.Zero, true)) {
File.Delete("sse.log");
printLog("Run main editor...");
Settings.Load();
// pass arguments of command line to opening
TextEditor te = new TextEditor(args);
Application.Run(te);
mutex.ReleaseMutex();
SingleInstanceManager.DeleteCommandLine();
printLog("Exit main editor.");
} else {
// only show message if opened normally without command line arguments
if (args.Length == 0)
MessageBox.Show("Another instance is already running!", "Sfall Script Editor");
else {
printLog(" Passed command argument to main editor.");
// pass command line arguments via file
SingleInstanceManager.SaveCommandLine(args);
// send message to other instance
SingleInstanceManager.SendEditorOpenMessage();
}
}
}
}
[DllImport("user32.dll", SetLastError = true)]
private static extern Int16 GetKeyState(Keys keys);
public static bool KeyHook(Keys key)
{
return ((GetKeyState(key) & 256) == 256);
}
public static void SetDoubleBuffered(Control cnt)
{
typeof (Control).InvokeMember("DoubleBuffered",
BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, cnt, new object[] {true});
}
public static void printLog(string log) { File.AppendAllText(Application.StartupPath + "\\sse.log", log + Environment.NewLine); }
}
}