Skip to content

Commit 74a89a8

Browse files
committed
fixed save_flight to append requared
per #55
1 parent cd7f8dc commit 74a89a8

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

SimConnect/SimConnect.py

+36-27
Original file line numberDiff line numberDiff line change
@@ -381,46 +381,56 @@ def load_flight_plan(self, pln_path):
381381
else:
382382
return False
383383

384-
def save_flight(self, flt_path, flt_title, flt_description):
384+
def save_flight(
385+
self,
386+
flt_path,
387+
flt_title,
388+
flt_description,
389+
flt_mission_type='FreeFlight',
390+
flt_mission_location='Custom departure',
391+
flt_original_flight='',
392+
flt_flight_type='NORMAL'):
385393
hr = self.dll.FlightSave(self.hSimConnect, flt_path.encode(), flt_title.encode(), flt_description.encode(), 0)
386-
if self.IsHR(hr, 0):
387-
return True
388-
else:
394+
if not self.IsHR(hr, 0):
389395
return False
390396

397+
dicp = self.flight_to_dic(flt_path)
398+
if 'MissionType' not in dicp['Main']:
399+
dicp['Main']['MissionType'] = flt_mission_type
400+
401+
if 'MissionLocation' not in dicp['Main']:
402+
dicp['Main']['MissionLocation'] = flt_mission_location
403+
404+
if 'FlightType' not in dicp['Main']:
405+
dicp['Main']['FlightType'] = flt_flight_type
406+
407+
if 'OriginalFlight' not in dicp['Main']:
408+
dicp['Main']['OriginalFlight'] = flt_original_flight
409+
self.dic_to_flight(dicp, flt_path)
410+
411+
return False
412+
391413
def get_paused(self):
392414
hr = self.dll.RequestSystemState(
393415
self.hSimConnect,
394416
self.dll.EventID.EVENT_SIM_PAUSED,
395417
b"Sim"
396418
)
397419

398-
# not working
399-
# def dic_to_flight(self, dic):
400-
# data_folder = os.path.dirname(os.path.realpath(__file__))
401-
# file_to_open = os.path.join(data_folder, "TEMP.FLT")
402-
# if os.path.isfile(file_to_open):
403-
# os.remove(file_to_open)
404-
# with open(file_to_open, "w") as tempfile:
405-
# for root in dic:
406-
# tempfile.write("\n[%s]\n" % root)
407-
# for member in dic[root]:
408-
# tempfile.write("%s=%s\n" % (member, dic[root][member]))
409-
# if os.path.isfile(file_to_open):
410-
# self.load_flight(file_to_open)
411-
412-
def flight_to_dic(self):
413-
data_folder = os.path.dirname(os.path.realpath(__file__))
414-
file_to_open = os.path.join(data_folder, "TEMP.FLT")
415-
if os.path.isfile(file_to_open):
416-
os.remove(file_to_open)
417-
self.save_flight(file_to_open, "Flight", "Supper Cool flight")
418-
while not os.path.isfile(file_to_open):
420+
def dic_to_flight(self, dic, fpath):
421+
with open(fpath, "w") as tempfile:
422+
for root in dic:
423+
tempfile.write("\n[%s]\n" % root)
424+
for member in dic[root]:
425+
tempfile.write("%s=%s\n" % (member, dic[root][member]))
426+
427+
def flight_to_dic(self, fpath):
428+
while not os.path.isfile(fpath):
419429
pass
420430
time.sleep(0.5)
421431
dic = {}
422432
index = ""
423-
with open(file_to_open, "r") as tempfile:
433+
with open(fpath, "r") as tempfile:
424434
for line in tempfile.readlines():
425435
if line[0] == '[':
426436
index = line[1:-2]
@@ -429,5 +439,4 @@ def flight_to_dic(self):
429439
if index != "" and line != '\n':
430440
temp = line.split("=")
431441
dic[index][temp[0]] = temp[1].strip()
432-
os.remove(file_to_open)
433442
return dic

0 commit comments

Comments
 (0)