-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPLAHelper.cs
89 lines (82 loc) · 2 KB
/
PLAHelper.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace PLAHConsole
{
class PLAHelper
{
static void Main( string[] args )
{
StreamReader i = new StreamReader("savedpositions.txt");
StreamWriter o = new StreamWriter( "plhudairports.txt", false );
o.Write(":AIRPORTS\r\nhex\r\n");
o.Write( convert( i.ReadToEnd() ) );
o.Write("\r\nend");
i.Close();
o.Close();
}
static string convert(string savedpositions) {
string res = "";
string[] lines = savedpositions.Split('\n', '\r');
string __l = "";
try {
bool skip = false;
foreach(string line in lines) {
if( skip )
{
skip = false;
continue;
}
if( line.Length < 10 )
{
continue;
}
if( line.StartsWith(";") )
{
skip = true;
continue;
}
__l = line;
string[] parts = line.Split( ',' );
float x = float.Parse(parts[1].Replace('.', ','));
float y = float.Parse(parts[2].Replace('.', ','));
float z = float.Parse(parts[3].Replace('.', ',')) - 1f;
string comment = line.Split( '/' )[2].Substring(1);
res += f2h( x ) + " " + f2h(y) + " " + f2h(z);
if( comment.Length == 0 )
{
res += " ";
}
else
{
comment = comment + " (" + (int) z + " FT)";
res += " " + b2h( new byte[] { BitConverter.GetBytes( comment.Length + 1 )[0] } );
res += " \"" + comment.Replace(' ', '_') + "\"";
res += " 00";
res += "\n";
}
}
}
catch( Exception r )
{
res = r.Message + "\n" + r.StackTrace + "\n" + __l;
}
res += "00000000";
return res;
}
static string f2h(float fNum)
{
return b2h(BitConverter.GetBytes( fNum ));
}
static string b2h( byte[] b )
{
StringBuilder sb = new StringBuilder();
for( int i = 0; i < b.Length; i++ ) {
sb.Append( b[i].ToString( "X2" ) );
}
return sb.ToString();
}
}
}