Exemple #1
0
        private void DownloadAndApplyUpdate(object sender, DoWorkEventArgs e)
        {
            void pCallback(long done, long total)
            {
                ProgressValue = done;
                ProgressMax   = total;
                var hrDone  = ByteSize.FromBytes(done).ToString(@"0.00");
                var hrTotal = ByteSize.FromBytes(total).ToString(@"0.00");

                ProgressText = M3L.GetString(M3L.string_downloadingUpdate) + $@" {hrDone} / {hrTotal}";
            }

            var    downloadLinks = new string[] { PrimaryDownloadLink, BackupDownloadLink };
            string errorMessage  = null;

            foreach (var downloadLink in downloadLinks)
            {
                var updateFile = OnlineContent.DownloadToMemory(downloadLink, pCallback);
                ProgressText = M3L.GetString(M3L.string_preparingToApplyUpdate);
                if (updateFile.errorMessage == null)
                {
                    ProgressIndeterminate = true;
                    ApplyUpdateFromStream(updateFile.result);
                    return; //do not loop.
                }
                else
                {
                    Log.Error(@"Error downloading update: " + updateFile.errorMessage);
                    Analytics.TrackEvent(@"Error downloading update", new Dictionary <string, string>()
                    {
                        { @"Error message", updateFile.errorMessage }
                    });
                    errorMessage = updateFile.errorMessage;
                }
            }
            Application.Current.Dispatcher.Invoke(delegate
            {
                M3L.ShowDialog(Window.GetWindow(this), errorMessage, M3L.GetString(M3L.string_errorDownloadingUpdate), MessageBoxButton.OK, MessageBoxImage.Error);
                OnClosing(DataEventArgs.Empty);
            });
        }
        private void DownloadAndApplyUpdate(object sender, DoWorkEventArgs e)
        {
            void pCallback(long done, long total)
            {
                ProgressValue = done;
                ProgressMax   = total;
                ProgressText  = $"Downloading update {ByteSize.FromBytes(done)} / {ByteSize.FromBytes(total)}";
            }

            //debug
            var downloadLinks = new string[] { PrimaryDownloadLink, BackupDownloadLink };
            // string l = "https://github.com/ME3Tweaks/ME3TweaksModManager/releases/download/0.0.0.1/UpdateTest2.7z";
            string errorMessage = null;

            foreach (var downloadLink in downloadLinks)
            {
                var updateFile = OnlineContent.DownloadToMemory(downloadLink, pCallback);
                ProgressText          = "Preparing to apply update";
                ProgressIndeterminate = true;
                if (updateFile.errorMessage == null)
                {
                    ApplyUpdateFromStream(updateFile.result);
                    return; //do not loop.
                }
                else
                {
                    Log.Error("Error downloading update: " + updateFile.errorMessage);
                    Analytics.TrackEvent("Error downloading update", new Dictionary <string, string>()
                    {
                        { "Error message", updateFile.errorMessage }
                    });
                    errorMessage = updateFile.errorMessage;
                }
            }
            Application.Current.Dispatcher.Invoke(delegate
            {
                Xceed.Wpf.Toolkit.MessageBox.Show(Window.GetWindow(this), errorMessage, "Error downloading update", MessageBoxButton.OK, MessageBoxImage.Error);
                OnClosing(DataEventArgs.Empty);
            });
        }
Exemple #3
0
        /// <summary>
        /// Gets the path to the GUI library specified by the DLC name. Returns null if the library is not found and could not be downloaded.
        /// If Download is specified this call should run on a background thread only.
        /// </summary>
        /// <param name="dlcname">DLC mod to lookup library for</param>
        /// <param name="download">Download library if missing. If this is false and library is missing the value returned will be null</param>
        /// <returns>Path to library, null if it does not exist.</returns>
        public static string GetUILibraryPath(string dlcname, bool download, Action <long, long> progressCallback = null)
        {
            string libraryFolder = Path.Combine(Utilities.GetAppDataFolder(), @"UIModLibrary");
            string libraryPath   = Path.Combine(libraryFolder, dlcname + @".zip");

            if (File.Exists(libraryPath))
            {
                return(libraryPath);
            }

            if (!Directory.Exists(libraryFolder) && !download)
            {
                return(null);
            }
            if (!File.Exists(libraryPath) && !download)
            {
                return(null);
            }

            if (download)
            {
                Directory.CreateDirectory(libraryFolder);
                Log.Information(@"Downloading UI library for " + dlcname);
                var downloaded = OnlineContent.DownloadToMemory(M3_UILIBRARY_ROOT + dlcname + @".zip", progressCallback);
                if (downloaded.errorMessage == null)
                {
                    File.WriteAllBytes(libraryPath, downloaded.result.ToArray());
                    Log.Information(@"Downloaded UI library for " + dlcname);
                    return(libraryPath);
                }
                else
                {
                    Log.Error(@"Error downloading UI library: " + downloaded.errorMessage);
                    return(null);
                }
            }

            return(null);
        }
Exemple #4
0
        private void UpdateModMakerMod(OnlineContent.ModMakerModUpdateInfo mui)
        {
            //throw new NotImplementedException();
            NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"ModmakerModUpdaterThread-" + mui.mod.ModName);

            nbw.WorkerReportsProgress = true;
            nbw.ProgressChanged      += (a, b) =>
            {
                if (b.UserState is double d)
                {
                    mainwindow.TaskBarItemInfoHandler.ProgressValue = d;
                }
            };
            nbw.DoWork += (a, b) =>
            {
                mui.DownloadButtonText = M3L.GetString(M3L.string_compiling);

                OperationInProgress  = true;
                mui.UpdateInProgress = true;
                mui.Indeterminate    = false;

                mui.UIStatusString = M3L.GetString(M3L.string_downloadingDelta);
                var normalEndpoint = OnlineContent.ModmakerModsEndpoint + mui.ModMakerId;
                var lzmaEndpoint   = normalEndpoint + @"&method=lzma";

                string modDelta = null;

                //Try LZMA first
                try
                {
                    var download = OnlineContent.DownloadToMemory(lzmaEndpoint);
                    if (download.errorMessage == null)
                    {
                        mui.UIStatusString = M3L.GetString(M3L.string_decompressingDelta);
                        // OK
                        var decompressed = SevenZipHelper.LZMA.DecompressLZMAFile(download.result.ToArray());
                        modDelta = Encoding.UTF8.GetString(decompressed);
                    }
                    else
                    {
                        Log.Error(@"Error downloading lzma mod delta to memory: " + download.errorMessage);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(@"Error downloading LZMA mod delta to memory: " + e.Message);
                }

                if (modDelta == null)
                {
                    //failed to download LZMA.
                    var download = OnlineContent.DownloadToMemory(normalEndpoint);
                    if (download.errorMessage == null)
                    {
                        //OK
                        modDelta = Encoding.UTF8.GetString(download.result.ToArray());
                    }
                    else
                    {
                        Log.Error(@"Error downloading decompressed mod delta to memory: " + download.errorMessage);
                    }
                }

                void setOverallMax(int max)
                {
                    mui.OverallProgressMax = max;
                }

                void setOverallValue(int current)
                {
                    mui.OverallProgressValue = current;
                    nbw.ReportProgress(0, current * 1.0 / mui.OverallProgressMax);
                    if (current > mui.OverallProgressMax)
                    {
                        Debugger.Break();
                    }
                }

                void setCurrentTaskString(string str)
                {
                    mui.UIStatusString = str;
                }

                if (modDelta != null)
                {
                    var compiler = new ModMakerCompiler(mui.ModMakerId);
                    //compiler.SetCurrentMaxCallback = SetCurrentMax;
                    //compiler.SetCurrentValueCallback = SetCurrentProgressValue;
                    compiler.SetOverallMaxCallback   = setOverallMax;
                    compiler.SetOverallValueCallback = setOverallValue;
                    //compiler.SetCurrentTaskIndeterminateCallback = SetCurrentTaskIndeterminate;
                    compiler.SetCurrentTaskStringCallback = setCurrentTaskString;
                    //compiler.SetModNameCallback = SetModNameOrDownloadText;
                    //compiler.SetCompileStarted = CompilationInProgress;
                    //compiler.SetModNotFoundCallback = ModNotFound;
                    Mod m = compiler.DownloadAndCompileMod(modDelta);
                    if (m != null)
                    {
                        try
                        {
                            File.WriteAllText(System.IO.Path.Combine(Utilities.GetModmakerDefinitionsCache(), mui.ModMakerId + @".xml"), modDelta);
                        }
                        catch (Exception e)
                        {
                            Log.Error(@"Couldn't cache modmaker xml file: " + e.Message);
                        }

                        mui.DownloadButtonText = M3L.GetString(M3L.string_updated);
                        mui.UIStatusString     = M3L.GetString(M3L.string_interp_modMakerCodeX, mui.ModMakerId);
                        mui.UpdateInProgress   = false;
                        mui.CanUpdate          = false;
                        AnyModUpdated          = true;
                    }
                    else
                    {
                        mui.UpdateInProgress   = false;
                        mui.DownloadButtonText = M3L.GetString(M3L.string_compilingFailed);
                        mui.UpdateInProgress   = false;
                    }
                }
            };
            nbw.RunWorkerCompleted += (a, b) =>
            {
                if (b.Error != null)
                {
                    Log.Error($@"Exception occured in {nbw.Name} thread: {b.Error.Message}");
                }
                Analytics.TrackEvent(@"Updated mod", new Dictionary <string, string>()
                {
                    { @"Type", @"ModMaker" },
                    { @"ModName", mui.mod.ModName },
                    { @"Result", mui.CanUpdate ? @"Success" : @"Failed" }
                });

                mainwindow.TaskBarItemInfoHandler.ProgressState = TaskbarItemProgressState.None;
                OperationInProgress = false;
                CommandManager.InvalidateRequerySuggested();
            };
            mainwindow.TaskBarItemInfoHandler.ProgressValue = 0;
            mainwindow.TaskBarItemInfoHandler.ProgressState = TaskbarItemProgressState.Normal;
            nbw.RunWorkerAsync();
        }
Exemple #5
0
            private void ToggleDisabler()
            {
                NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"OIGDisablerThread");

                nbw.DoWork += async(a, b) =>
                {
                    if (!Utilities.IsGameRunning(Game))
                    {
                        var d3d9Path = Path.Combine(MEDirectories.ExecutableDirectory(SelectedTarget), @"d3d9.dll");
                        if (!File.Exists(d3d9Path))
                        {
                            if (File.Exists(Utilities.GetOriginOverlayDisableFile()))
                            {
                                Log.Information(@"Installing origin overlay disabler from cache to " + d3d9Path);
                                try
                                {
                                    File.Copy(Utilities.GetOriginOverlayDisableFile(), d3d9Path);
                                }
                                catch (Exception e)
                                {
                                    Log.Error($@"Error installing d3d9.dll: {e.Message}");
                                }
                            }
                            else
                            {
                                var client = new GitHubClient(new ProductHeaderValue(@"ME3TweaksModManager"));
                                try
                                {
                                    var releases = await client.Repository.Release.GetAll(@"ME3Tweaks", @"d3d9-blank-proxy");

                                    if (releases.Count > 0)
                                    {
                                        Log.Information(@"Parsing release information from github");

                                        //The release we want to check is always the latest with assets that is not a pre-release
                                        var latestRel = releases.FirstOrDefault(x => !x.Prerelease && x.Assets.Count > 0);
                                        if (latestRel != null)
                                        {
                                            var downloadUrl        = latestRel.Assets[0].BrowserDownloadUrl;
                                            var downloadedZipAsset = OnlineContent.DownloadToMemory(downloadUrl);
                                            using var zf = new ZipArchive(downloadedZipAsset.result);
                                            var d3d9 = zf.Entries.First(x => x.FullName == @"d3d9.dll");
                                            if (d3d9 != null)
                                            {
                                                await using var data = d3d9.Open();
                                                var memStream = new MemoryStream();
                                                data.CopyTo(memStream);
                                                try
                                                {
                                                    Log.Information(@"Installing origin overlay disabler from memory to " + d3d9Path);
                                                    memStream.WriteToFile(d3d9Path); //install
                                                    Log.Information(@"Caching d3d9 disabler");
                                                    memStream.WriteToFile(Utilities.GetOriginOverlayDisableFile());
                                                }
                                                catch (Exception e)
                                                {
                                                    Log.Error(@"Cannot install/cache disabler: " + e.Message);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Log.Error(@"Error checking for tool update: " + e);
                                }
                            }
                        }
                        else
                        {
                            Log.Information(@"Deleting " + d3d9Path);
                            try
                            {
                                File.Delete(d3d9Path);
                            }
                            catch (Exception e)
                            {
                                Log.Error($@"Error deleting d3d9.dll: {e.Message}");
                            }
                        }
                    }
                };
                nbw.RunWorkerCompleted += (await, b) =>
                {
                    SetupDisablerButtonText();
                };
                nbw.RunWorkerAsync();
            }
Exemple #6
0
        private void UpdateModMakerMod(OnlineContent.ModMakerModUpdateInfo mui)
        {
            //throw new NotImplementedException();
            NamedBackgroundWorker bw = new NamedBackgroundWorker(@"ModmakerModUpdaterThread-" + mui.mod.ModName);

            bw.DoWork += (a, b) =>
            {
                mui.DownloadButtonText = M3L.GetString(M3L.string_compiling);

                OperationInProgress  = true;
                mui.UpdateInProgress = true;
                mui.Indeterminate    = false;

                mui.UIStatusString = M3L.GetString(M3L.string_downloadingDelta);
                var normalEndpoint = OnlineContent.ModmakerModsEndpoint + mui.ModMakerId;
                var lzmaEndpoint   = normalEndpoint + @"&method=lzma";

                string modDelta = null;

                //Try LZMA first
                try
                {
                    var download = OnlineContent.DownloadToMemory(lzmaEndpoint);
                    if (download.errorMessage == null)
                    {
                        mui.UIStatusString = M3L.GetString(M3L.string_decompressingDelta);
                        // OK
                        var decompressed = SevenZipHelper.LZMA.DecompressLZMAFile(download.result.ToArray());
                        modDelta = Encoding.UTF8.GetString(decompressed);
                        // File.WriteAllText(@"C:\users\mgamerz\desktop\decomp.txt", modDelta);
                    }
                    else
                    {
                        Log.Error(@"Error downloading lzma mod delta to memory: " + download.errorMessage);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(@"Error downloading LZMA mod delta to memory: " + e.Message);
                }

                if (modDelta == null)
                {
                    //failed to download LZMA.
                    var download = OnlineContent.DownloadToMemory(normalEndpoint);
                    if (download.errorMessage == null)
                    {
                        //OK
                        modDelta = Encoding.UTF8.GetString(download.result.ToArray());
                    }
                    else
                    {
                        Log.Error(@"Error downloading decompressed mod delta to memory: " + download.errorMessage);
                    }
                }

                void setOverallMax(int max)
                {
                    mui.OverallProgressMax = max;
                }

                void setOverallValue(int current)
                {
                    mui.OverallProgressValue = current;
                    if (current > mui.OverallProgressMax)
                    {
                        Debugger.Break();
                    }
                }

                void setCurrentTaskString(string str)
                {
                    mui.UIStatusString = str;
                }

                if (modDelta != null)
                {
                    var compiler = new ModMakerCompiler(mui.ModMakerId);
                    //compiler.SetCurrentMaxCallback = SetCurrentMax;
                    //compiler.SetCurrentValueCallback = SetCurrentProgressValue;
                    compiler.SetOverallMaxCallback   = setOverallMax;
                    compiler.SetOverallValueCallback = setOverallValue;
                    //compiler.SetCurrentTaskIndeterminateCallback = SetCurrentTaskIndeterminate;
                    compiler.SetCurrentTaskStringCallback = setCurrentTaskString;
                    //compiler.SetModNameCallback = SetModNameOrDownloadText;
                    //compiler.SetCompileStarted = CompilationInProgress;
                    //compiler.SetModNotFoundCallback = ModNotFound;
                    Mod m = compiler.DownloadAndCompileMod(modDelta);
                    File.WriteAllText(System.IO.Path.Combine(Utilities.GetModmakerDefinitionsCache(), mui.ModMakerId + @".xml"), modDelta);
                    mui.DownloadButtonText = M3L.GetString(M3L.string_updated);
                    mui.UIStatusString     = M3L.GetString(M3L.string_interp_modMakerCodeX, mui.ModMakerId);
                    mui.UpdateInProgress   = false;
                    mui.CanUpdate          = false;
                    AnyModUpdated          = true;
                    //b.Result = m;
                }
            };
            bw.RunWorkerCompleted += (a, b) =>
            {
                OperationInProgress = false;
                CommandManager.InvalidateRequerySuggested();
            };
            bw.RunWorkerAsync();
        }
        private void StartCompiler()
        {
            CompileInProgress = true;
            Settings.Save(); //Persist controller mixin option, keybinds injection
            NamedBackgroundWorker nbw = new NamedBackgroundWorker(@"ModmakerCompiler");

            nbw.DoWork += (a, b) =>
            {
                string modDelta = null;

                if (int.TryParse(ModMakerCode, out var code))
                {
                    DownloadAndModNameText = @"Downloading mod delta from ME3Tweaks";
                    var normalEndpoint = OnlineContent.ModmakerModsEndpoint + code;
                    var lzmaEndpoint   = normalEndpoint + @"&method=lzma";


                    //Try LZMA first
                    try
                    {
                        var download = OnlineContent.DownloadToMemory(lzmaEndpoint, (done, total) =>
                        {
                            if (total != -1)
                            {
                                var suffix             = $@" {(done * 100.0 / total).ToString(@"0")}%"; //do not localize
                                DownloadAndModNameText = M3L.GetString(M3L.string_downloadingModDeltaFromME3Tweaks) + suffix;
                            }
                            else
                            {
                                DownloadAndModNameText = M3L.GetString(M3L.string_downloadingModDeltaFromME3Tweaks);
                            }
                        });
                        if (download.errorMessage == null)
                        {
                            DownloadAndModNameText = M3L.GetString(M3L.string_decompressingDelta);
                            // OK
                            var decompressed = SevenZipHelper.LZMA.DecompressLZMAFile(download.result.ToArray());
                            modDelta = Encoding.UTF8.GetString(decompressed);
                            // File.WriteAllText(@"C:\users\mgamerz\desktop\decomp.txt", modDelta);
                        }
                        else
                        {
                            Log.Error(@"Error downloading lzma mod delta to memory: " + download.errorMessage);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(@"Error downloading LZMA mod delta to memory: " + e.Message);
                    }

                    if (modDelta == null)
                    {
                        //failed to download LZMA.
                        var download = OnlineContent.DownloadToMemory(normalEndpoint, (done, total) =>
                        {
                            var suffix             = $" {(done * 100.0 / total).ToString(@"0")}%"; //do not localize
                            DownloadAndModNameText = M3L.GetString(M3L.string_downloadingModDeltaFromME3Tweaks) + suffix;
                        });
                        if (download.errorMessage == null)
                        {
                            //OK
                            modDelta = Encoding.UTF8.GetString(download.result.ToArray());
                        }
                        else
                        {
                            Log.Error(@"Error downloading decompressed mod delta to memory: " + download.errorMessage);
                        }
                    }
                }
                else if (File.Exists(LocalFilePath))
                {
                    modDelta = File.ReadAllText(LocalFilePath);
                }


                if (modDelta != null)
                {
                    KeepOpenWhenThreadFinishes = false;
                    var compiler = new ModMakerCompiler(code);
                    compiler.SetCurrentMaxCallback               = SetCurrentMax;
                    compiler.SetCurrentValueCallback             = SetCurrentProgressValue;
                    compiler.SetOverallMaxCallback               = SetOverallMax;
                    compiler.SetOverallValueCallback             = SetOverallValue;
                    compiler.SetCurrentTaskIndeterminateCallback = SetCurrentTaskIndeterminate;
                    compiler.SetCurrentTaskStringCallback        = SetCurrentTaskString;
                    compiler.SetModNameCallback     = SetModNameOrDownloadText;
                    compiler.SetCompileStarted      = CompilationInProgress;
                    compiler.SetModNotFoundCallback = ModNotFound;
                    compiler.NotifySomeDLCIsMissing = NotifySomeDLCIsMissing;
                    Mod m = compiler.DownloadAndCompileMod(modDelta);
                    if (m != null && !LocalFileOption)
                    {
                        var sanitizedname = Utilities.SanitizePath(m.ModName);
                        File.WriteAllText(Path.Combine(Utilities.GetModmakerDefinitionsCache(), $@"{code}-{sanitizedname}.xml"), modDelta);
                    }
                    b.Result = m;
                }
            };
            nbw.RunWorkerCompleted += (a, b) =>
            {
                if (b.Error != null)
                {
                    Log.Error($@"Exception occured in {nbw.Name} thread: {b.Error.Message}");
                }
                CompileInProgress = false;
                if (!KeepOpenWhenThreadFinishes && b.Result is Mod m)
                {
                    OnClosing(new DataEventArgs(m));
                }
                else
                {
                    CloseProgressPanel();
                    ShowCloseButton = true;
                }
                CommandManager.InvalidateRequerySuggested();
            };
            nbw.RunWorkerAsync();
        }