Esempio n. 1
0
        public static bool EnsureCriticalFiles()
        {
            //7-zip
            try
            {
                string sevenZDLL = Utilities.Get7zDllPath();
                if (!File.Exists(sevenZDLL) || Utilities.CalculateMD5(sevenZDLL) != "72491c7b87a7c2dd350b727444f13bb4")
                {
                    foreach (var staticurl in StaticFilesBaseEndpoints)
                    {
                        try
                        {
                            using var wc = new ShortTimeoutWebClient();
                            {
                                var fullURL = staticurl + "7z.dll";
                                Log.Information("Downloading 7z.dll: " + fullURL);
                                wc.DownloadFile(fullURL, sevenZDLL);
                                break; //No more loops
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error($"Could not download 7z.dll from endpoint {staticurl} {e.Message}");
                        }
                    }
                }

                if (File.Exists(sevenZDLL))
                {
                    Log.Information("Setting 7z dll path: " + sevenZDLL);
                    var p = Path.GetFullPath(sevenZDLL);
                    SevenZip.SevenZipBase.SetLibraryPath(sevenZDLL);
                }
                else
                {
                    Log.Fatal("Unable to load 7z dll! File doesn't exist: " + sevenZDLL);
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception ensuring critical files: " + App.FlattenException(e));
                return(false);
            }

            return(true);
        }
        public static bool EnsureStaticAssets()
        {
            string[] objectInfoFiles = { "ME1ObjectInfo.json", "ME2ObjectInfo.json", "ME3ObjectInfo.json" };
            string   localBaseDir    = Utilities.GetObjectInfoFolder();

            try
            {
                foreach (var info in objectInfoFiles)
                {
                    var localPath = Path.Combine(localBaseDir, info);
                    if (!File.Exists(localPath))
                    {
                        foreach (var staticurl in StaticFilesBaseEndpoints)
                        {
                            var fullURL = staticurl + "objectinfos/" + info;

                            try
                            {
                                using var wc = new ShortTimeoutWebClient();
                                Log.Information("Downloading static asset: " + fullURL);
                                wc.DownloadFile(fullURL, localPath);
                                break;
                            }
                            catch (Exception e)
                            {
                                Log.Error($"Could not download {info} from endpoint {fullURL} {e.Message}");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception trying to ensure static assets: " + e.Message);
                Crashes.TrackError(new Exception(@"Could not download static supporting files: " + e.Message));
                return(false);
            }

            return(true);
        }