Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
2146 lines (1941 loc) · 77.2 KB

File metadata and controls

2146 lines (1941 loc) · 77.2 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
#if !CONSOLE
using System.Windows.Forms;
#endif
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO;
using System.Drawing;
using System.Net;
using System.Configuration;
using System.Globalization;
using System.Reflection;
using System.Security.Cryptography;
using JoinFS.Properties;
using System.Collections.Concurrent;
namespace JoinFS
{
public class Main
{
// default settings
public const int DEFAULT_ACTIVITY_CIRCLE = 40;
public const int DEFAULT_FOLLOW_DISTANCE = 80;
const int MAX_INSTANCES = 4;
/// <summary>
/// Current version
/// </summary>
private static string version = "0.0.0";
// Version getter
public static string Version
{
get { return version; }
}
/// <summary>
/// Current name
/// </summary>
private static string name = "";
// Name getter
public static string Name
{
get { return name; }
}
/// <summary>
/// Storage path
/// </summary>
public string storagePath = ".";
/// <summary>
/// Documents path
/// </summary>
public string documentsPath = ".";
/// <summary>
/// Unique identifier for this installation
/// </summary>
public Guid guid = Guid.Empty;
public uint uuid = 0;
// modules
public Sim sim;
public Network network;
public Substitution substitution;
public Recorder recorder;
public AddressBook addressBook;
public Log log;
public Monitor monitor;
public Euroscope euroscope;
public Whazzup whazzup;
public Notes notes;
public Stats stats;
public VariableMgr variableMgr;
/// <summary>
/// Settings
/// </summary>
public bool settingsPortEnabled = false;
public ushort settingsPort = Network.DEFAULT_PORT;
public string settingsNickname = "";
public bool settingsConnectOnLaunch = false;
public int settingsActivityCircle = DEFAULT_ACTIVITY_CIRCLE;
public bool settingsAtc = false;
public string settingsAtcAirport = "";
public bool settingsHub = false;
public string settingsHubDomain = "";
public string settingsHubName = "";
public string settingsHubAbout = "";
public string settingsHubVoip = "";
public string settingsHubEvent = "";
public string settingsPassword = "";
public bool settingsWhazzup = false;
public bool settingsWhazzupPublic = false;
public bool settingsMultiObjects = false;
public bool settingsMinimized = false;
public bool settingsNoGui = false;
public bool settingsNoSim = false;
public bool settingsLoop = false;
public bool settingsXplane = false;
public bool settingsTcas = false;
public bool settingsScan = false;
public bool settingsUseAIFeatures = false;
#if XPLANE || CONSOLE
public bool settingsGenerateCsl = false;
public bool settingsSkipCsl = false;
#endif
public string settingsLocalAddress = "";
#if CONSOLE
public bool settingsBackground = false;
public string settingsComsWebhookUri = "";
public string settingsComsWebhookMethod = "PUT";
public bool settingsWebSocket = false;
public int settingsWebSocketPort = 8765;
public bool settingsWebSocketLog = false;
WebhookService webhookService;
WebSocketServer webSocketServer;
#endif
/// <summary>
/// shutdown JoinFS
/// </summary>
public string shutdown = null;
/// <summary>
/// Multithreading lock object
/// </summary>
public object conch = new();
/// <summary>
/// instance ID
/// </summary>
public int instanceCount = 1;
/// <summary>
/// Thread for updates
/// </summary>
private readonly Thread _workThread;
/// <summary>
/// Finish work flag
/// </summary>
public volatile bool workFinish = false;
/// <summary>
/// Close main
/// </summary>
public void Close()
{
// check for thread
if (_workThread != null)
{
// notify thread
workFinish = true;
_workThread.Join(5000);
}
// close systems
if (network != null)
{
// leave session
network.Leave();
// close network
network.localNode.Close();
// monitor
MonitorEvent("Closed UDP port " + network.localNode.GetLocalNuid().port);
}
sim ?. Close();
#if CONSOLE
webSocketServer?.Close();
#endif
// save settings
Settings.Default.Save();
}
// record time at launch
readonly Stopwatch stopwatch;
// get time since launch
public double ElapsedTime
{
get
{
return (double)stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
}
}
/// <summary>
/// Construct main
/// </summary>
public Main()
{
try
{
UpgradeSettingsIfRequired();
// get product name and file version
Assembly assembly = Assembly.GetExecutingAssembly();
// get name
name = assembly.GetName().Name;
// construct three part version number
FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
version = info.FileMajorPart.ToString() + '.' + info.FileMinorPart.ToString() + '.' + info.FileBuildPart.ToString();
// get settings
settingsPortEnabled = Settings.Default.LocalPortEnabled;
settingsPort = Settings.Default.LocalPort;
settingsNickname = Settings.Default.Nickname;
settingsConnectOnLaunch = Settings.Default.ConnectOnLaunch;
settingsActivityCircle = Settings.Default.ActivityCircle;
settingsAtc = Settings.Default.Atc;
settingsAtcAirport = Settings.Default.AtcAirport.ToUpper();
settingsHub = Settings.Default.Hub;
settingsHubDomain = Settings.Default.HubAddress;
settingsHubName = Settings.Default.HubName;
settingsHubAbout = Settings.Default.HubAbout;
settingsHubVoip = Settings.Default.HubVoIP;
settingsHubEvent = Settings.Default.HubEvent;
settingsPassword = Settings.Default.Password;
settingsWhazzup = Settings.Default.Whazzup;
settingsWhazzupPublic = Settings.Default.WhazzupGlobal;
settingsMultiObjects = Settings.Default.MultipleObjectsEveryone;
settingsLoop = Settings.Default.Loop;
settingsXplane = Settings.Default.XPlane;
settingsTcas = Settings.Default.TCAS;
settingsScan = Settings.Default.ModelScanOnConnection;
settingsUseAIFeatures = Settings.Default.UseAIFeatures;
#if XPLANE || CONSOLE
settingsGenerateCsl = Settings.Default.GenerateCsl;
settingsSkipCsl = Settings.Default.SkipCsl;
#endif
#if SERVER
settingsNoSim = true;
#endif
#if XPLANE
settingsXplane = true;
#endif
// command line optins
bool doCreate = false;
string doJoin = null;
bool doGlobal = false;
string doPlay = "";
bool doRecord = false;
bool doQuit = false;
#if XPLANE || CONSOLE
bool doPlugin = false;
#endif
string simFolder = "";
// get command line
string[] args = Environment.GetCommandLineArgs();
// process command line
for (int index = 1; index < args.Length; index++)
{
// check for option
if (args[index].Length > 0 && args[index][0] == '-')
{
// handle -- type options as well
string option = args[index].StartsWith("--") ? args[index][1..] : args[index];
// process option
switch (option)
{
case "-play":
// next parameter
index++;
// check for file name
if (index < args.Length)
{
// play specified recording
doPlay = args[index];
}
break;
case "-record":
// start new recording
doRecord = true;
break;
case "-loop":
// enable looping
settingsLoop = true;
break;
case "-create":
// create network
doCreate = true;
break;
case "-rejoin":
// join network
doJoin = Settings.Default.JoinAddress;
break;
case "-join":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// join network
doJoin = args[index];
}
break;
case "-port":
// next parameter
index++;
// check for file name
if (index < args.Length)
{
// get port
if (ushort.TryParse(args[index], NumberStyles.Number, CultureInfo.InvariantCulture, out settingsPort))
{
// use port
settingsPortEnabled = true;
}
}
break;
case "-hub":
// enable hub mode
settingsHub = true;
break;
case "-localaddress":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
settingsLocalAddress = args[index];
}
break;
case "-hubdomain":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// update hub domain
settingsHubDomain = args[index];
}
break;
case "-hubname":
// next parameter
index++;
// check for parameter
if (index < args.Length && args[index].Length >= 3)
{
// update hub name
settingsHubName = args[index];
}
break;
case "-hubabout":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// update hub about
settingsHubAbout = args[index];
}
break;
case "-hubvoip":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// update hub voice server
settingsHubVoip = args[index];
}
break;
case "-hubevent":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// update hub event
settingsHubEvent = args[index];
}
break;
case "-nickname":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// update nickname
settingsNickname = args[index];
}
break;
case "-activitycircle":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
if (int.TryParse(args[index], NumberStyles.Number, CultureInfo.InvariantCulture, out int val))
{
// update activity circle
settingsActivityCircle = val;
}
}
break;
case "-follow":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
if (Int32.TryParse(args[index], NumberStyles.Number, CultureInfo.InvariantCulture, out int val))
{
// update follow distance
Settings.Default.FollowDistance = val;
}
}
break;
case "-atc":
// enable ATC mode
settingsAtc = true;
break;
case "-airport":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// write airport
settingsAtcAirport = args[index][..Math.Min(4, args[index].Length)].ToUpper();
}
break;
case "-autobroadcast":
// update auto broadcast
Settings.Default.AutoBroadcast = true;
break;
case "-lowbandwidth":
// update low bandwidth enabled
Settings.Default.LowBandwidth = true;
break;
case "-minimize":
// minimize
settingsMinimized = true;
break;
case "-global":
doGlobal = true;
break;
case "-whazzup":
settingsWhazzup = true;
break;
case "-whazzup-public":
settingsWhazzup = true;
settingsWhazzupPublic = true;
break;
case "-nosim":
settingsNoSim = true;
settingsConnectOnLaunch = false;
break;
case "-nogui":
settingsNoGui = true;
break;
case "-quit":
doQuit = true;
settingsNoGui = true;
break;
case "-multiobjects":
settingsMultiObjects = true;
break;
case "-xplane":
settingsXplane = true;
break;
case "-tcas":
settingsTcas = true;
break;
case "-simfolder":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// get sim folder
simFolder = args[index];
}
break;
#if XPLANE || CONSOLE
case "-installplugin":
// do plugin
doPlugin = true;
break;
#endif
case "-password":
// next parameter
index++;
// check for parameter
if (index < args.Length)
{
// get password
settingsPassword = args[index];
}
break;
case "-scan":
settingsScan = true;
break;
#if XPLANE || CONSOLE
case "-generatecsl":
settingsGenerateCsl = true;
break;
case "-skipcsldone":
settingsSkipCsl = true;
break;
#endif
#if CONSOLE
case "-background":
settingsBackground = true;
break;
case "-comswebhookuri":
index++;
if (index < args.Length) settingsComsWebhookUri = args[index];
break;
case "-comswebhookmethod":
index++;
if (index < args.Length) settingsComsWebhookMethod = args[index].ToUpper();
break;
case "-websocket":
settingsWebSocket = true;
break;
case "-websocketport":
index++;
if (index < args.Length && int.TryParse(args[index], out int wsPort)) settingsWebSocketPort = wsPort;
break;
case "-websocketlog":
settingsWebSocketLog = true;
break;
case "-help":
Console.WriteLine(name + " (" + version + ")");
Console.WriteLine("");
Console.WriteLine("Usage: dotnet " + name + ".dll [options]");
Console.WriteLine("");
Console.WriteLine(" --create " + Resources.Strings.Options_Create);
Console.WriteLine(" --join <address> " + Resources.Strings.Options_Join);
Console.WriteLine(" --rejoin " + Resources.Strings.Options_Rejoin);
Console.WriteLine(" --global " + Resources.Strings.Options_Global);
Console.WriteLine(" --nickname <name> " + Resources.Strings.Options_Nickname);
Console.WriteLine(" --port " + Resources.Strings.Options_Port);
Console.WriteLine(" --localaddress <ip> Override local network address (use host LAN IP when running in Docker)");
Console.WriteLine(" --hub " + Resources.Strings.Tip_HubMode);
Console.WriteLine(" --hubdomain <domain> " + Resources.Strings.Tip_HubDomain);
Console.WriteLine(" --hubname <name> " + Resources.Strings.Tip_HubName);
Console.WriteLine(" --hubabout <details> " + Resources.Strings.Tip_HubAbout);
Console.WriteLine(" --hubvoip <details> " + Resources.Strings.Tip_HubVoice);
Console.WriteLine(" --hubevent <details> " + Resources.Strings.Tip_HubEvent);
Console.WriteLine(" --password <password> " + Resources.Strings.Tip_Password);
Console.WriteLine(" --play <.jfs file> " + Resources.Strings.Options_Play);
Console.WriteLine(" --record " + Resources.Strings.Options_Record);
Console.WriteLine(" --loop " + Resources.Strings.Tip_Loop);
Console.WriteLine(" --activitycircle <nm> " + Resources.Strings.Options_ActivityCircle);
Console.WriteLine(" --follow <nm> " + Resources.Strings.Options_Follow);
Console.WriteLine(" --atc " + Resources.Strings.Options_Atc);
Console.WriteLine(" --airport <code> " + Resources.Strings.Options_Airport);
Console.WriteLine(" --lowbandwidth " + Resources.Strings.Tip_LowBandwidth);
Console.WriteLine(" --whazzup " + Resources.Strings.Tip_Whazzup);
Console.WriteLine(" --whazzup-public " + Resources.Strings.Tip_WhazzupGlobal);
Console.WriteLine(" --minimize " + Resources.Strings.Options_Minimize);
Console.WriteLine(" --background " + Resources.Strings.Options_Background);
Console.WriteLine(" --nosim " + Resources.Strings.Options_NoSim);
Console.WriteLine(" --nogui " + Resources.Strings.Options_NoGui);
Console.WriteLine(" --multiobjects " + Resources.Strings.Tip_MultiObjects);
Console.WriteLine(" --simfolder \"<folder>\" " + Resources.Strings.Options_SimFolder);
Console.WriteLine(" --scan " + Resources.Strings.ScanForModels);
Console.WriteLine(" --generatecsl " + Resources.Strings.Option_GenerateCsl);
Console.WriteLine(" --skipcsldone " + Resources.Strings.Option_SkipCsl);
Console.WriteLine(" --xplane " + Resources.Strings.Tip_Xplane);
Console.WriteLine(" --installplugin " + Resources.Strings.Options_InstallPlugin);
Console.WriteLine(" --tcas " + Resources.Strings.Tip_TCAS);
Console.WriteLine(" --quit " + Resources.Strings.Options_Quit);
Console.WriteLine(" --help " + Resources.Strings.Options_Help);
Console.WriteLine(" --comswebhookuri <uri> Send COM1/COM2 changes as webhook POST/PUT/PATCH/GET to this URI");
Console.WriteLine(" --comswebhookmethod HTTP method for COM webhook (POST|PUT|PATCH|GET, default PUT)");
Console.WriteLine(" --websocket Enable WebSocket server broadcasting aircraft data");
Console.WriteLine(" --websocketport <port> WebSocket server port (default 8765)");
Console.WriteLine(" --websocketlog Log WebSocket events and webhook calls (default false)");
Console.WriteLine("");
Console.WriteLine("Interactive key commands:");
Console.WriteLine("");
Console.WriteLine("S Show session details");
Console.WriteLine("A Show aircraft details");
Console.WriteLine("Escape Close JoinFS");
Console.WriteLine("Ctrl + N Toggle the network connection");
Console.WriteLine("Ctrl + S Toggle the simulator connection");
Console.WriteLine("Ctrl + Q Scan for models");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("Install the X-Plane plugin:");
Console.WriteLine("");
Console.WriteLine("dotnet " + name + ".dll --installplugin --simfolder \"<folder>\"");
throw new Exception();
#endif
}
}
}
// create stopwatch
stopwatch = Stopwatch.StartNew();
// get all JoinFS instances
Process[] instances = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location));
// get this instance
Process thisInstance = System.Diagnostics.Process.GetCurrentProcess();
// check for quit
if (doQuit)
{
// for each instance
foreach (var instance in instances)
{
// check for this instance
if (instance.Id != thisInstance.Id)
{
// kill instance
instance.Kill();
}
}
// shutdown
shutdown = "";
}
// check for maximum instance count
if (instances.Length > MAX_INSTANCES)
{
// close
shutdown = Resources.Strings.MaxInstances;
}
try
{
// get storage path
storagePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), name);
// check if it does not exist
if (Directory.Exists(storagePath) == false)
{
// create storage path
Directory.CreateDirectory(storagePath);
}
// get documents path
documentsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), name);
// check if it does not exist
if (Directory.Exists(documentsPath) == false)
{
// create storage path
Directory.CreateDirectory(documentsPath);
}
}
catch (Exception ex)
{
ShowMessage(ex.Message);
}
// read guid
try
{
// check for invalid guid
if (Settings.Default.LastPosition == Guid.Empty)
{
// generate new one
Settings.Default.LastPosition = Guid.NewGuid();
}
// get guid
guid = Settings.Default.LastPosition;
}
catch
{
// create new guid
guid = Guid.NewGuid();
// save guid
Settings.Default.LastPosition = guid;
}
#if !NO_HUBS
// four byte identifier
uuid = Network.MakeUuid(guid);
#endif
// create monitor module
monitor = new Monitor(this);
#if FS2020
MonitorEvent("Starting JoinFS-FS2020 v" + version);
#elif FS2024
MonitorEvent("Starting JoinFS-FS2024 v" + version);
#elif XPLANE
MonitorEvent("Starting JoinFS-XPLANE v" + version);
#elif P3D
MonitorEvent("Starting JoinFS-P3D v" + version);
#elif FSX
MonitorEvent("Starting JoinFS-FSX v" + version);
#elif SERVER
MonitorEvent("Starting JoinFS-SERVER v" + version);
#elif CONSOLE
MonitorEvent("Starting JoinFS-CONSOLE v" + version);
#else
MonitorEvent("Starting JoinFS v" + version);
#endif
// create modules
log = new Log(this);
sim = new Sim(this);
network = new Network(this);
#if !SERVER
substitution = new Substitution(this);
// try to resolve the simulator folder from the simulator's own recorded
// install location before ever asking the user - see SimPathDetector
#if FS2020
if (substitution.EnsureFoldersConfigured("Microsoft Flight Simulator 2020", out string fs2020SimName) == false)
{
scheduleSimFolderPrompt = true;
pendingSimFolderName = fs2020SimName;
}
// no eager scan here - the FS2020 addons list isn't loaded until the sim connects
#elif FS2024
if (substitution.EnsureFoldersConfigured("Microsoft Flight Simulator 2024", out string fs2024SimName) == false)
{
scheduleSimFolderPrompt = true;
pendingSimFolderName = fs2024SimName;
}
// no eager scan here - FS2024 community models come from a live SimConnect request
#elif FSX
if (substitution.EnsureFoldersConfigured("Microsoft Flight Simulator X", out string fsxSimName))
{
substitution.Scan(false, fsxSimName);
}
else
{
scheduleSimFolderPrompt = true;
pendingSimFolderName = fsxSimName;
}
#elif P3D
if (substitution.EnsureFoldersConfigured("Prepar3D v5", out string p3dSimName))
{
substitution.Scan(false, p3dSimName);
}
else
{
scheduleSimFolderPrompt = true;
pendingSimFolderName = p3dSimName;
}
#elif XPLANE
if (substitution.EnsureFoldersConfigured("X-Plane", out string xplaneSimName))
{
substitution.Scan(false, xplaneSimName);
}
else
{
scheduleSimFolderPrompt = true;
pendingSimFolderName = xplaneSimName;
}
#endif
#endif
recorder = new Recorder(this);
addressBook = new AddressBook(this);
euroscope = new Euroscope(this);
whazzup = new Whazzup(this);
notes = new Notes(this);
stats = new Stats();
variableMgr = new VariableMgr(this);
#if !CONSOLE
// fetch the pilot's SimBrief flight plan on startup if a username is already saved -
// this is a cloud API call independent of the simulator, so it doesn't need to wait for a connection
if (string.IsNullOrWhiteSpace(Settings.Default.SimBriefUsername) == false)
{
_ = sim.RefreshUserFlightPlanFromSimBriefAsync();
}
#endif
// check for specified sim folder
if (simFolder.Length > 0)
{
// initialize sim folder
substitution.LoadFolders();
substitution.simFolder = simFolder;
substitution.SaveFolders();
Settings.Default.XPlaneFolder = simFolder;
}
#if NO_CREATE
// disable hub mode
doCreate = false;
settingsHub = false;
#endif
#if CONSOLE
// disable nogui option
settingsNoGui = true;
#endif
// load airports
LoadAirportDetails();
// load log
log.Load();
#if XPLANE || CONSOLE
// check for xplane
if (settingsXplane)
{
// load substitution
ScheduleSubstitutionLoad();
}
// check for install plugin
if (doPlugin)
{
sim.xplane.InstallPlugin(Settings.Default.XPlaneFolder);
shutdown = "Finished plugin install.";
}
#endif
// port
ushort port = settingsPortEnabled ? settingsPort : Network.DEFAULT_PORT;
// open port
if (network.localNode.Open(port))
{
// monitor
MonitorEvent("Opened UDP port " + port);
if (settingsHub)
{
// monitor
MonitorEvent("Started hub '" + settingsHubName + "'");
}
}
// check for Hub mode enabled
if (doCreate || settingsHub)
{
// leave network
network.ScheduleLeave();
// create network
network.ScheduleCreate();
}
// check for join global option
if (doGlobal || Settings.Default.Global)
{
// auto join
network.ScheduleJoinGlobal();
}
// check for join option
if (doJoin != null)
{
// join network
#if NO_HUBS
Join(Network.DecodeIP(doJoin.TrimStart(' ').TrimEnd(' ')));
#else
Join(doJoin.TrimStart(' ').TrimEnd(' '));
#endif
}
// check for play option
if (doPlay != "")
{
// try to open file
try
{
StreamReader stream = new(doPlay);
if (stream != null)
{
// try to open file
BinaryReader reader = new(stream.BaseStream);
if (reader != null)
{
// read recording
recorder.Read(reader);
// start playing
recorder.StartPlay();
}
}
}
catch (Exception ex)
{
ShowMessage(ex.Message);
}
}
// check for record option
if (doRecord)
{
// start recording
recorder.StartRecord(false);
}
// monitor
MonitorEvent("Start complete");
// start work thread
_workThread = new Thread(new ThreadStart(DoWork));
_workThread.Start();
#if CONSOLE
webhookService = settingsComsWebhookUri.Length > 0 ? new WebhookService(this) : null;
webSocketServer = settingsWebSocket ? new WebSocketServer(this) : null;
#endif
}
catch (Exception ex)
{
shutdown = "ERROR - " + ex.Message;
}
}
static void UpgradeSettingsIfRequired()
{
if (Settings.Default.MigratedSettings == false)
{
// Prevent multiple instances from upgrading settings at the same time.
System.Threading.Mutex mutex = new(false, "JoinFS_SettingsUpgrade_Mutex");
bool acquired = false;
try
{
try
{
acquired = mutex.WaitOne(5000);
}
catch (AbandonedMutexException)
{
// another process terminated while holding the mutex, we can continue
acquired = true;
}
try
{
// Try to upgrade settings. Only mark as migrated if Upgrade() succeeds.
Settings.Default.Upgrade();
Settings.Default.MigratedSettings = true;
Settings.Default.Save();
}
catch (System.Configuration.ConfigurationErrorsException ex)
{
// Log and continue with defaults; do not let this abort startup.
System.Diagnostics.Trace.WriteLine("Settings upgrade failed: " + ex);
}
catch (Exception ex)
{
// Catch-all to avoid crashing the application during startup.
System.Diagnostics.Trace.WriteLine("Settings upgrade unexpected error: " + ex);
}
}
finally
{
try
{
if (acquired && mutex != null)
{
mutex.ReleaseMutex();
}
}
catch { }
try { mutex?.Dispose(); } catch { }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.