// Add New Script Modification Behaviour private async void AddNewScriptModButton_Click(object sender, RoutedEventArgs e) { this.AddNewScriptModButton.IsEnabled = false; ScriptMod newScriptMod = await this.ScriptModAPI.CreateScriptMod("New Mod Name", 0, "New Mod Description", false); this.ScriptMods.Insert(0, newScriptMod); await this.ScriptModAPI.UpdateScriptModOrderIndexes(this.ScriptMods); this.AddNewScriptModButton.IsEnabled = true; }
private async void ScriptModsDataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { ScriptMod editedScriptMod = e.Row.Item as ScriptMod; string whichColumn = e.Column.Header as string; if (whichColumn == "Name") { if (String.IsNullOrWhiteSpace(editedScriptMod.Name)) { editedScriptMod.Name = await this.ScriptModAPI.GetOldNameBeforeIllegalEdit(editedScriptMod.Id); return; } else if (editedScriptMod.Name == await this.ScriptModAPI.GetOldNameBeforeIllegalEdit(editedScriptMod.Id)) { return; } else { Regex invalidFileNameCharsRegex = new Regex("[" + Regex.Escape(new string(Path.GetInvalidFileNameChars())) + "]"); if (invalidFileNameCharsRegex.IsMatch(editedScriptMod.Name)) { editedScriptMod.Name = await this.ScriptModAPI.GetOldNameBeforeIllegalEdit(editedScriptMod.Id); return; } } bool changeNameIsSuccess = await this.ScriptModAPI.UpdateScriptModName(editedScriptMod.Id, editedScriptMod.Name); if (!changeNameIsSuccess) { editedScriptMod.Name = await this.ScriptModAPI.GetOldNameBeforeIllegalEdit(editedScriptMod.Id); MetroWindow metroWindow = (Application.Current.MainWindow as MetroWindow); // needed to access ShowMessageAsync() method in MetroWindow string errorDialogTitle = "Unable to rename modification"; string errorDialogMessage = "Unable to rename this modification. The folder and/or its files may be in use by an application (or alternatively the name has unknown invalid characters or is too long)."; MessageDialogResult result = await metroWindow.ShowMessageAsync(errorDialogTitle, errorDialogMessage, MessageDialogStyle.Affirmative); } } else if (whichColumn == "Description") { await this.ScriptModAPI.UpdateScriptModDescription(editedScriptMod.Id, editedScriptMod.Description); } }
private async void MoveScriptModDownButton_Click(object sender, RoutedEventArgs e) { if (this.ModIndexRearrangeAllowed) { this.ModIndexRearrangeAllowed = false; ScriptMod chosenScriptMod = ((FrameworkElement)sender).DataContext as ScriptMod; if (this.ScriptMods.ElementAt(this.ScriptMods.Count - 1).Id == chosenScriptMod.Id) { this.ModIndexRearrangeAllowed = true; return; } int oldIndex = this.ScriptMods.IndexOf(chosenScriptMod); int newIndex = oldIndex + 1; this.ScriptMods.Move(oldIndex, newIndex); await Task.Run(() => this.ScriptModAPI.UpdateScriptModOrderIndexes(this.ScriptMods)); this.ModIndexRearrangeAllowed = true; } }
private async void ScriptModDGIsEnabled_Click(object sender, EventArgs e) { ScriptMod editedScriptMod = ((FrameworkElement)sender).DataContext as ScriptMod; // the sender ScriptMod object from the datagrid await this.ScriptModAPI.UpdateScriptModIsEnabled(editedScriptMod.Id, editedScriptMod.IsEnabled); }
private async Task MoveScriptModsBack() { MetroWindow metroWindow = null; this.Dispatcher.Invoke(() => metroWindow = (Application.Current.MainWindow as MetroWindow)); this.GTAVLaunchProgress.SetTitle("Moving script modifications back"); this.GTAVLaunchProgress.SetMessage("..."); foreach (ScriptMod scriptMod in this.InsertedScriptMods) { this.GTAVLaunchProgress.SetMessage(scriptMod.Name + " - moving back..."); bool currScriptModMoveBackSuccess = await Task.Run(() => this.GTAV.MoveScriptModBack(scriptMod)); if (!currScriptModMoveBackSuccess) { await this.Dispatcher.Invoke(async() => await metroWindow.ShowMessageAsync("Failed to move back script modification files", "Couldn't move back some files belonging to '" + scriptMod.Name + "' from GTAV directory during clean-up." + " You may have to manually go to GTAV's folder to find these files and put them back in this modification.")); } scriptMod.IsInserted = false; await this.ScriptModsUserControl.ScriptModAPI.UpdateScriptModIsInserted(scriptMod.Id, false); } this.InsertedScriptMods.Clear(); this.GTAVLaunchProgress.SetMessage("Deleting remaining non-game folders with no files..."); await this.GTAV.DeleteRemainingRootFoldersWithNoFiles(); this.GTAVLaunchProgress.SetMessage("Checking for non-game unknown remaining and non-empty folders..."); List <DirectoryInfo> unknownFolders = await this.GTAV.DiscoverUnknownLeftoverNonEmptyFolders(); if (unknownFolders.Any()) { ScriptMod scriptModForUnknownFolders = await this.ScriptModsUserControl.ScriptModAPI.CreateScriptMod( "Leftover Mod Folders - Review", 0, "The folders inside this modification are leftover non-empty (non-game) folders after GTAV Story with script mods was launched.\n" + "They have been preserved for review as they may contain files generated by a modification that you would like to keep (by moving these folders to the belonging modification).", false); await this.Dispatcher.Invoke(async() => { this.ScriptModsUserControl.ScriptMods.Insert(0, scriptModForUnknownFolders); await this.ScriptModsUserControl.ScriptModAPI.UpdateScriptModOrderIndexes(this.ScriptModsUserControl.ScriptMods); }); try { foreach (DirectoryInfo dir in unknownFolders) { string unknownFolderFullDest = Path.Combine(SettingsHandler.ModsDirectory, "Script Mods", scriptModForUnknownFolders.Name, dir.Name); Directory.CreateDirectory(unknownFolderFullDest); Utils.CopyDirectoryWithContents(dir.FullName, unknownFolderFullDest); Directory.Delete(dir.FullName, true); } } catch (Exception) { await this.Dispatcher.Invoke(async() => await metroWindow.ShowMessageAsync("Error", "Unable to move some unknown non-game and non-modification folders in GTAV directory.")); } } this.GTAVLaunchProgress.SetMessage("Checking for non-game unknown remaining files..."); List <FileInfo> unknownFiles = await this.GTAV.DiscoverUnknownLeftoverFiles(); if (unknownFiles.Any()) { ScriptMod scriptModForUnknownFiles = await this.ScriptModsUserControl.ScriptModAPI.CreateScriptMod( "Leftover Mod Files - Review", 0, "The files inside this modification are leftover (non-game) files after GTAV Story with script mods was launched.\n" + "They have been preserved for review as they may contain files generated by a modification that you would like to keep (by moving these files to the belonging modification).", false); await this.Dispatcher.Invoke(async() => { this.ScriptModsUserControl.ScriptMods.Insert(0, scriptModForUnknownFiles); await this.ScriptModsUserControl.ScriptModAPI.UpdateScriptModOrderIndexes(this.ScriptModsUserControl.ScriptMods); }); foreach (FileInfo file in unknownFiles) { File.Move(file.FullName, Path.Combine(SettingsHandler.ModsDirectory, "Script Mods", scriptModForUnknownFiles.Name, file.Name)); } } }