-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuide.cs
More file actions
227 lines (195 loc) · 8.66 KB
/
Guide.cs
File metadata and controls
227 lines (195 loc) · 8.66 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
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using OccultWatcher.SDK;
using System.IO.Compression;
using System.Configuration;
using System.Diagnostics;
using OccultWatcher.Guide.Properties;
namespace OccultWatcher.Guide
{
public class OWGuide : IOWAddin
{
public const string OWGuideAddinName = "OWGuide.addinName";
public const string OWGuideStartGuide = "OWGuide.startGuide";
public const string OWGuideConfigTitle = "OWGuide.configTitle";
public const string OWGuideBrowse = "OWGuide.btnBrowse";
public const string OWGuideOptional = "OWGuide.lblOptional";
public const string OWGuideGuidePath = "OWGuide.lblGuidePath";
public const string OWGuideAlwaysInNewInstance = "OWGuide.cbxAlwaysInNewInstance";
public const string OWGuideCouldNotFindPath = "OWGuide.couldNotFindPath";
public const string OWGuideAdditionalCommandLineArguments = "OWGuide.lblAdditionalArguments";
public const string OWGuideAddinCredits = "OWGuide.aboutMessage";
private readonly int START_GUIDE = 1;
private readonly int CHANGE_LANGUAGE = 2;
bool isEnglish = false;
bool isGerman = false;
private IOWHost m_HostInfo = null;
private IOWResourceProvider m_ResourceProvider = null;
private Process m_CurrentGuideProcess = null;
public OWAddinAction[] ADDIN_ACTIONS = null;
internal string GetResourceString(string resourceName, string defaultValue)
{
string resourceValue = null;
if (isEnglish)
resourceValue = defaultValue;
else if (isGerman)
resourceValue = GetGermanResource(resourceName);
if (resourceValue != null)
{
return resourceValue;
}
if (m_ResourceProvider == null)
// Backwards compatibility with older versions of OW
return defaultValue;
else
return m_ResourceProvider.GetResourceString(resourceName, defaultValue);
}
private string GetGermanResource(string resourceId)
{
if (resourceId == OWGuideAddinName)
return "OW Guide Add-in";
if (resourceId == OWGuideStartGuide)
return "Zeige Ereignis in Guide";
if (resourceId == OWGuideConfigTitle)
return "OW Guide Add-in Konfiguration";
if (resourceId == OWGuideBrowse)
return "Durchsuchen ...";
if (resourceId == OWGuideOptional)
return "Optional: Name einer Guide-Konfiguration (genau 8 Buchstaben lang)";
if (resourceId == OWGuideGuidePath)
return "Dateipfad angeben um Guide zu starten";
if (resourceId == OWGuideCouldNotFindPath)
return "Pfad '{0}' konnte nicht gefunden werden";
if (resourceId == OWGuideAlwaysInNewInstance)
return "Ereignis in neuem Guide-Fenster öffnen";
if (resourceId == OWGuideAdditionalCommandLineArguments)
return "Optional: Zusätzliche Befehlszeilen-Argumente";
return null;
}
void IOWAddin.InitializeAddin(IOWHost hostInfo)
{
m_HostInfo = hostInfo;
m_ResourceProvider = hostInfo as IOWResourceProvider;
GuideConfig.LoadRegistryConfig();
SetLanguage(m_HostInfo.CurrentLanguage);
ADDIN_ACTIONS = new OWAddinAction[]
{
new OWAddinAction(START_GUIDE, GetResourceString(OWGuideStartGuide, "Show Event in Guide"), OWAddinActionType.SelectedEventAction, Properties.Resources.Details.ToBitmap()),
new OWAddinAction(CHANGE_LANGUAGE, "Language Change", OWAddinActionType.EventReceiver, null),
};
}
void IOWAddin.FinalizeAddin()
{
// Do nothing special
}
OWAddinInfo IOWAddin.GetAddinInfo()
{
return new OWAddinInfo(GetResourceString(OWGuideAddinName, "OW Guide Add-in"), true, Properties.Resources.AddinImg.ToBitmap());
}
void IOWAddin.Configure(IWin32Window owner)
{
guideFrmConfig guideFrm = new guideFrmConfig(this);
guideFrm.ShowDialog(owner);
}
IEnumerable<OWAddinAction> IOWAddin.SupportedActions()
{
return ADDIN_ACTIONS;
}
bool IOWAddin.ShouldDisplayAction(int actionId, IOWAsteroidEvent astEvent)
{
// Our actions will be always displayed if the path to Guide has been configured
return File.Exists(GuideConfig.GuidePath);
}
void IOWAddin.ExecuteAction(
int actionId,
IOWAsteroidEvent astEvent,
IWin32Window owner,
OWEventArguments eventArgs)
{
if (actionId == START_GUIDE)
{
if (astEvent != null)
{
IOWLocalEventData siteData = astEvent as IOWLocalEventData;
IOWAsteroidEvent2 evt2 = astEvent as IOWAsteroidEvent2;
if (siteData != null && evt2 != null && File.Exists(GuideConfig.GuidePath))
{
DateTime dateAndTime = siteData.EventTime;
string date = dateAndTime.ToString("yyyyMMdd HH:mm:ssUT");
// Read coordintes
double coord_RA = evt2.Occelmnt.StarRAHours;
double coord_DEC = evt2.Occelmnt.StarDEDeg;
// Convert RA-format from hh.hhhhh into hhmmss.ssss
if (coord_RA < 0.0)
{
coord_RA = coord_RA + 24.0;
}
// coordinate setting for Guide: hhmmss.ssss,dd.dddd
string coord = string.Concat(AstroConvert.ToStringValue(coord_RA, "HHMMSS.T"), ",", AstroConvert.ToStringValue(coord_DEC, "+DDMMSS"));
// Build Guide Options
// https://www.projectpluto.com/random.htm#command_line
// Format: -tyyyymmdd hh:mm:ss.ssss -ohhmmss.ssss,dd.ddddd
string guideOptions;
if (GuideConfig.GuideConfiguration == "")
{
guideOptions = string.Concat("-t", date, " -o", coord, " " + GuideConfig.CommandLineArguments);
}
else
{
guideOptions = string.Concat("-m", GuideConfig.GuideConfiguration, ".mar ", "-t", date, " -o", coord, " " + GuideConfig.CommandLineArguments);
}
if (!GuideConfig.AlwaysNewInstance)
{
if (m_CurrentGuideProcess != null &&
!m_CurrentGuideProcess.HasExited)
{
try
{
m_CurrentGuideProcess.Kill();
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
}
}
}
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = Path.GetDirectoryName(GuideConfig.GuidePath);
startInfo.FileName = GuideConfig.GuidePath;
startInfo.Verb = "runas";
startInfo.Arguments = guideOptions;
startInfo.ErrorDialog = true;
m_CurrentGuideProcess = Process.Start(startInfo);
}
}
}
if (actionId == CHANGE_LANGUAGE)
{
if (eventArgs.OWEventId == OWEventArguments.EVT_CURR_LANGUAGE_CHANGED)
{
SetLanguage((int) eventArgs.Args);
}
}
}
private void SetLanguage(int langId)
{
isEnglish = false;
isGerman = false;
switch (langId)
{
case 1:
isEnglish = true;
break;
case 3:
isGerman = true;
break;
}
}
}
}