mracko / MSFS-Mobile-Companion-App

Mobile Companion App for MSFS 2020
GNU Affero General Public License v3.0
355 stars 42 forks source link

Remove need for settings.txt? #40

Open Revel8804 opened 3 years ago

Revel8804 commented 3 years ago

So in theory this should work for both steam and MS store if I am reading right. I don't have the Steam version so I can not confirm. It is basically importing the windows environment variable for localappdata and using that instead of having to specify in the settings.txt file.

Let me know your thoughts. I hope this marks up correctly.

so glass_server.py..... At the beginning I added....

from flask import Flask, jsonify, render_template, request
from SimConnect import *
from time import sleep, localtime
import random
import logging
import math
import socket
import asyncio
from threading import Thread, local
import datetime
import os   #######My Additions are right here#######
localappdata = os.getenv('localappdata')   #######My Additions are right here#######

print (socket.gethostbyname(socket.gethostname()))

ui_friendly_dictionary = {}
event_name = None
value_to_use = None)

Then in the load_fltpln function i changed it to......

    fltpln = []
    @app.route('/fltpln', methods=["POST"])
    def load_fltpln():
        # Load Settings - MSFS Install Location
        try:
            fltpln_dir = localappdata + "\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe" ##My Additions are right here##
            print(fltpln_dir)
            try:
                # MS Store
                fltpln_dir_full = fltpln_dir + "\LocalState\MISSIONS\Custom\CustomFlight\CUSTOMFLIGHT.FLT"
                with open(fltpln_dir_full, 'r') as fltpln:
                    fltpln_lines = fltpln.readlines()
            except:
                # Steam
                fltpln_dir_full = fltpln_dir + "\MISSIONS\Custom\CustomFlight\CUSTOMFLIGHT.FLT"
                with open(fltpln_dir_full, 'r') as fltpln:
                    fltpln_lines = fltpln.readlines()

            # Process Flight Plan Function
            def latlong_dec_convert(to_convert):
mracko commented 3 years ago

Thanks for the tip! I've been thinking about doing something similar, however, I don't know if this works when you have: a) custom install folder for Windows Store b) custom install folder for Steam

I wanted to make it as flexible as possible, so I've decided to go with a text file. I'll leave the issue/suggestion open because I might revisit it later.

Revel8804 commented 3 years ago

oh have an update on this one. Its been a minute and I forgot to add it. While working on my magic painting for the planes I learned about the file.

MSFSdir\localcache\User.Cfg.opt

From my understanding at least on the windows store version. the game will always install to C:\Users\\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe and will have the usercfg.opt file.

The last line in that file will have the external location that you want your packages installed to.

InstalledPackagesPath "C:\Users\kenny\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\Packages"

I know the steam version will have that file there too, but if you tell steam to install to another location or drive, other than a file search I'm not sure how to find it.

i can not test the steam version either since I don't own it on steam.

Revel8804 commented 3 years ago

also I have been out for a bit. The new updates and changes, ARE AMAZING!.

Just wanted to say good work and I appreciate that you are making and updating this.

E1xP commented 2 years ago

I have a steam version it seem whatever you place the game the CUSTOMFLIGHT.FLT will at the same place. (except the username) And got another problem. In python \ is a convert chart. And when it use in locate a file should use r before the string or using \ or / in the string. It seem in this programe if reading fail. It also tell user to check the setting path. Maybe using except FileNotFoundError: to tell user about config wrong will better.