├── .gitmodules ├── .github ├── dependabot.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── dotnet-core.yml │ └── dotnet-core-default.yml ├── README.md ├── CONTRIBUTING.md ├── FFXIV_Modding_Tool ├── FFXIV_Modding_Tool.csproj ├── Configuration.cs ├── Validation.cs ├── FirstTimeSetup.cs ├── Arguments.cs └── Program.cs ├── .all-contributorsrc ├── CODE_OF_CONDUCT.md ├── INSTALL_BUILD.md ├── .gitignore └── LICENSE /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "xivModdingFramework"] 2 | path = xivModdingFramework 3 | url = https://github.com/TexTools/xivModdingFramework 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: nuget 4 | directory: "/FFXIV_Modding_Tool" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | target-branch: dependabot 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ****FFMT**** 2 | 3 | FFMT is on an extended hiatus. 4 | 5 | Important bug fixes and framework updates may still be released on a best effort basis. 6 | No packages will be provided. 7 | 8 | --- 9 | **Please consider using penumbra instead of FFMT:** 10 | 11 | https://reniguide.info/#installpenumbra 12 | --- 13 | 14 | 15 | If you are desperate for FFMT, you can find [Installation, usage and build instructions here](INSTALL_BUILD.md) 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a bug report 4 | title: "[ISSUE] " 5 | labels: bug 6 | assignees: fosspill 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Run command '...' 16 | 2. See error 17 | 18 | **Expected behavior** 19 | A clear and concise description of what you expected to happen. 20 | 21 | **Desktop (please complete the following information):** 22 | - OS: [e.g. Linux] 23 | - FFMT Version: [e.g. v0.3] 24 | 25 | **Additional context** 26 | Add any other context about the problem here. 27 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-core.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core Build 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | submodules: true 14 | - name: Setup .NET Core 15 | uses: actions/setup-dotnet@v1 16 | with: 17 | dotnet-version: 3.1.301 18 | - name: Build Framework 19 | run: dotnet build --no-incremental -c Release xivModdingFramework/xivModdingFramework/xivModdingFramework.csproj -o FFXIV_Modding_Tool/references/ 20 | - name: Build FFMT 21 | run: dotnet build --no-incremental -c Release FFXIV_Modding_Tool/FFXIV_Modding_Tool.csproj 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE] " 5 | labels: enhancement 6 | assignees: fosspill 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-core-default.yml: -------------------------------------------------------------------------------- 1 | name: .NET Core Default 2 | 3 | on: 4 | push: 5 | branches: 6 | - default 7 | 8 | jobs: 9 | build: 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | submodules: true 17 | - name: Setup .NET Core 18 | uses: actions/setup-dotnet@v1 19 | with: 20 | dotnet-version: 3.1.301 21 | - name: Build Framework 22 | run: dotnet build --no-incremental -c Release xivModdingFramework/xivModdingFramework/xivModdingFramework.csproj -o FFXIV_Modding_Tool/references/ 23 | - name: Build FFMT 24 | run: dotnet build --no-incremental -c Release FFXIV_Modding_Tool/FFXIV_Modding_Tool.csproj 25 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | ## Testing, testing and more testing. 4 | This project really needs more testing by more people on more systems. 5 | We do test on Windows and Linux, but the team does not have access to a Mac for testing. 6 | 7 | ### How to test 8 | 1. Grab the latest executable 9 | 2. Follow the usage guide, see if the functions work as expected. 10 | 3. If you do not use TexTools nor play FFXIV, feel free to create an issue so we can send you some test data. 11 | 12 | ## Suggest changes (to code, to guidelines or to plans) 13 | We want this project to end up with decent quality, but as inexperienced C# developers it can be hard to keep proper standards up while making the application actually work. 14 | 15 | Please suggest changes that would be for the better of the project, code or team! 16 | -------------------------------------------------------------------------------- /FFXIV_Modding_Tool/FFXIV_Modding_Tool.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | ffmt 7 | 0.10.1 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | references/xivModdingFramework.dll 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "kainz0r", 10 | "name": "kainz0r", 11 | "avatar_url": "https://avatars0.githubusercontent.com/u/6439314?v=4", 12 | "profile": "https://github.com/kainz0r", 13 | "contributions": [ 14 | "bug", 15 | "userTesting" 16 | ] 17 | }, 18 | { 19 | "login": "taylor85345", 20 | "name": "taylor85345", 21 | "avatar_url": "https://avatars0.githubusercontent.com/u/36456160?v=4", 22 | "contributions": [ 23 | "bug", 24 | "userTesting" 25 | ] 26 | }, 27 | { 28 | "login": "shinnova", 29 | "name": "shinnova", 30 | "avatar_url": "https://avatars0.githubusercontent.com/u/12647312?v=4", 31 | "profile": "https://github.com/shinnova", 32 | "contributions": [ 33 | "code", 34 | "example", 35 | "maintenance", 36 | "review" 37 | ] 38 | }, 39 | { 40 | "login": "fosspill", 41 | "name": "fosspill", 42 | "avatar_url": "https://avatars3.githubusercontent.com/u/1491401?v=4", 43 | "profile": "https://github.com/fosspill", 44 | "contributions": [ 45 | "code", 46 | "example", 47 | "doc", 48 | "ideas" 49 | ] 50 | }, 51 | { 52 | "login": "hybridindie", 53 | "name": "Johnny D", 54 | "avatar_url": "https://avatars.githubusercontent.com/u/20465?v=4", 55 | "profile": "https://github.com/hybridindie", 56 | "contributions": [ 57 | "userTesting", 58 | "bug" 59 | ] 60 | }, 61 | { 62 | "login": "zeparu", 63 | "name": "zepar", 64 | "avatar_url": "https://avatars.githubusercontent.com/u/21054889?v=4", 65 | "profile": "https://github.com/zeparu", 66 | "contributions": [ 67 | "userTesting" 68 | ] 69 | } 70 | ], 71 | "contributorsPerLine": 7, 72 | "projectName": "FFXIV_Modding_Tool", 73 | "projectOwner": "fosspill", 74 | "repoType": "github", 75 | "repoHost": "https://github.com", 76 | "skipCi": true, 77 | "commitConvention": "none" 78 | } 79 | -------------------------------------------------------------------------------- /FFXIV_Modding_Tool/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.IO; 3 | using Salaros.Configuration; 4 | using System.Collections.Generic; 5 | 6 | namespace FFXIV_Modding_Tool.Configuration 7 | { 8 | public class Config 9 | { 10 | public static string configFile = Path.Combine(MainClass._projectconfDirectory.FullName, "config.cfg"); 11 | MainClass main = new MainClass(); 12 | 13 | public void CreateDefaultConfig() 14 | { 15 | if (!Directory.Exists(MainClass._projectconfDirectory.FullName)) 16 | Directory.CreateDirectory(MainClass._projectconfDirectory.FullName); 17 | var configFileFromString = new ConfigParser(@"[Directories] 18 | # All paths can be written with or without escaping 19 | 20 | # Full path to game install, including 'FINAL FANTASY XIV - A Realm Reborn' 21 | # Example locations: 22 | # MacOS: /Users//Library/Application Support/FINAL FANTASY XIV ONLINE/Bottles/published_Final_Fantasy/drive_c/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn 23 | # Linux: /path/to/WINEBOTTLE/drive_c/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn 24 | # Windows: C:\Program Files (x86)\SquareEnix\FINAL FANTASY XIV - A Realm Reborn 25 | GameDirectory 26 | 27 | # Full path to directory with your index backups, this can be any directory where you wish to store your backups 28 | BackupDirectory 29 | 30 | # Full path to directory where FFXIV.cfg and character data is saved, including 'FINAL FANTASY XIV - A Realm Reborn' 31 | # Example locations: 32 | # MacOS: /Users//My Documents/My Games/FINAL FANTASY XIV - A Realm Reborn 33 | # Linux: /path/to/WINEBOTTLE/drive_c/users//My Documents/My Games/FINAL FANTASY XIV - A Realm Reborn 34 | # Windows: C:\users\\My Documents\My Games\FINAL FANTASY XIV - A Realm Reborn 35 | ConfigDirectory", 36 | new ConfigParserSettings 37 | { 38 | MultiLineValues = MultiLineValues.Simple | MultiLineValues.AllowValuelessKeys | MultiLineValues.QuoteDelimitedValues, 39 | Culture = new CultureInfo("en-US") 40 | }); 41 | configFileFromString.Save(configFile); 42 | main.PrintMessage($"Config file saved to {configFile}", 1); 43 | } 44 | 45 | public string ReadConfig(string target) 46 | { 47 | var configFileFromPath = new ConfigParser(configFile); 48 | string targetDirectory = configFileFromPath.GetValue("Directories", target); 49 | if (!string.IsNullOrEmpty(targetDirectory)) 50 | { 51 | //Workaround for issue #166 52 | //If Directory is quoted on both ends: ignore both quotes. 53 | List quotelist = new List(); 54 | quotelist.AddRange("\'\""); 55 | if(quotelist.Contains(targetDirectory[0]) && quotelist.Contains(targetDirectory[targetDirectory.Length -1])){ 56 | targetDirectory = targetDirectory.Substring(1, targetDirectory.Length -2); 57 | } 58 | return targetDirectory; 59 | } 60 | else 61 | return ""; 62 | } 63 | public void SaveConfig(string target, string value) 64 | { 65 | var configFileFromPath = new ConfigParser(configFile); 66 | configFileFromPath.SetValue("Directories", target, value); 67 | configFileFromPath.Save(configFile); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at github.eloelo@spamgourmet.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /INSTALL_BUILD.md: -------------------------------------------------------------------------------- 1 | ![GitHub release (latest by date)](https://img.shields.io/github/v/release/fosspill/FFXIV_Modding_Tool?label=version) [![CodeFactor](https://www.codefactor.io/repository/github/fosspill/ffxiv_modding_tool/badge/default)](https://www.codefactor.io/repository/github/fosspill/ffxiv_modding_tool/overview/default) ![GitHub All Releases](https://img.shields.io/github/downloads/fosspill/FFXIV_Modding_Tool/total) ![.NET Core Default](https://github.com/fosspill/FFXIV_Modding_Tool/workflows/.NET%20Core%20Default/badge.svg) [![Documentation](https://img.shields.io/badge/-Documentation%20-important)](https://ffmt.pwd.cat) 2 | 3 | [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-) 4 | 5 | 6 | Using XIVLauncher? Test [Penumbra](https://raw.githubusercontent.com/xivdev/Penumbra/master/repo.json "Penumbra") instead of `FFMT` 7 | 8 | 9 | 10 | # FFMT - FFXIV Modding Tool 11 | 12 | 13 | **FFMT** is a crossplatform CLI alternative to the Windows-Only *Textools* for Mac, Windows and Linux! 14 | 15 | **This project is NOT affiliated with FFXIV_TexTools_UI** 16 | 17 | Depends on the latest stable version (2.3.7.1) of *[xivModdingFramework](https://github.com/TexTools/xivModdingFramework)* 18 | 19 | [![](https://asciinema.org/a/hfp5oOSjhGGz55mX9g9TVRS3l.svg)](https://asciinema.org/a/hfp5oOSjhGGz55mX9g9TVRS3l) 20 | 21 | Documentation with examples: https://ffmt.pwd.cat/ 👈 22 | 23 | # Features! 24 | List is sorted by priority 25 | - [x] [Full Mac, Linux and Windows support](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/1) 26 | - [x] [**Import modpacks (ttmp files)**](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/2) 27 | - [x] [Storable configuration for important directories](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/3) 28 | - [x] [Backup and restore of important game files](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/4) 29 | - [x] [Manage mods (enable/disable)](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/27) 30 | - [ ] [Import specific textures / models (including advanced import options)](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/5) 31 | - [ ] [Export specific textures / models](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/6) 32 | - [x] [Check for problems](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/7) 33 | - [x] [ModPack creation v1](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/8) 34 | - [ ] [TexTools interchangeability](https://github.com/fosspill/FFXIV_TexTools_CLI/issues/67) 35 | 36 | ## Current Development Status 37 | 38 | Maintenance and bug fixes only, so don't expect any huge new features. 39 | PRs are, however, very welcome. 40 | 41 | We'll keep updating FFMT when the need arises. 42 | 43 | ## How to Install, Build and Use: 44 | 45 | https://ffmt.pwd.cat 46 | 47 | ### Building from source 48 | 49 | https://ffmt.pwd.cat/#/userguide/technical/building 50 | 51 | License 52 | ---- 53 | 54 | GNU General Public License v3.0 55 | 56 | 57 | **Free Software, Hell Yeah!** 58 | 59 | ## Contributors ✨ 60 | 61 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |

kainz0r

🐛 📓

taylor85345
🐛 📓

shinnova

💻 💡 🚧 👀

fosspill

💻 💡 📖 🤔

Johnny D

📓 🐛

zepar

📓
76 | 77 | 78 | 79 | 80 | 81 | 82 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! 83 | -------------------------------------------------------------------------------- /FFXIV_Modding_Tool/Validation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Collections.Generic; 4 | using Newtonsoft.Json; 5 | using xivModdingFramework.General.Enums; 6 | using xivModdingFramework.Helpers; 7 | using xivModdingFramework.Mods.DataContainers; 8 | 9 | namespace FFXIV_Modding_Tool.Validation 10 | { 11 | public class Validators 12 | { 13 | public Validators(){} 14 | MainClass main = new MainClass(); 15 | 16 | public bool ValidateDirectory(DirectoryInfo directory, string directoryType) 17 | { 18 | if (!directory.Exists) 19 | return false; 20 | else 21 | { 22 | switch (directoryType) 23 | { 24 | case "BackupDirectory": 25 | return true; 26 | case "GameDirectory": 27 | if (directory.GetFiles("*.index").Length == 0) 28 | return false; 29 | return true; 30 | case "ConfigDirectory": 31 | if (directory.GetFiles("FFXIV*.cfg").Length == 0) 32 | return false; 33 | return true; 34 | default: 35 | return false; 36 | } 37 | } 38 | } 39 | 40 | public bool ValidateTTMPFile(string ttmpPath) 41 | { 42 | if (File.Exists(ttmpPath) && (ttmpPath.EndsWith(".ttmp") || ttmpPath.EndsWith(".ttmp2"))) 43 | return true; 44 | return false; 45 | } 46 | 47 | public bool ValidateBackups() 48 | { 49 | main.PrintMessage("Checking backups before proceeding..."); 50 | bool keepGoing = true; 51 | bool problemFound = false; 52 | if (MainClass._backupDirectory == null) 53 | { 54 | main.PrintMessage($"No backup directory specified, can't check the status of backups.\nYou are strongly recommended to add a backup directory in {Path.Combine(MainClass._projectconfDirectory.FullName, "config.cfg")} and running the 'backup' command before proceeding", 2); 55 | problemFound = true; 56 | } 57 | else if (MainClass._gameDirectory == null) 58 | { 59 | main.PrintMessage("No game directory specified, can't check if backups are up to date", 2); 60 | problemFound = true; 61 | } 62 | else 63 | { 64 | var filesToCheck = new XivDataFile[] { XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui }; 65 | ProblemChecker problemChecker = new ProblemChecker(MainClass._indexDirectory); 66 | foreach (var file in filesToCheck) 67 | { 68 | if (!File.Exists(Path.Combine(MainClass._backupDirectory.FullName, $"{file.GetDataFileName()}.win32.index"))) 69 | { 70 | main.PrintMessage($"One or more index files could not be found in {MainClass._backupDirectory.FullName}. Creating new ones or downloading them from the TexTools discord is recommended", 2); 71 | problemFound = true; 72 | break; 73 | } 74 | var outdatedBackupsCheck = problemChecker.CheckForOutdatedBackups(file, MainClass._backupDirectory); 75 | outdatedBackupsCheck.Wait(); 76 | if (!outdatedBackupsCheck.Result) 77 | { 78 | main.PrintMessage($"One or more index files are out of date in {MainClass._backupDirectory.FullName}. Recreating or downloading them from the TexTools discord is recommended", 2); 79 | problemFound = true; 80 | break; 81 | } 82 | } 83 | } 84 | if (problemFound){ 85 | if (PromptContinuation("Would you like to back up now?", true)){ 86 | main.BackupIndexes(); 87 | keepGoing = true; 88 | } else { 89 | keepGoing = PromptContinuation(); 90 | } 91 | } 92 | else 93 | main.PrintMessage("All backups present and up to date", 1); 94 | return keepGoing; 95 | } 96 | 97 | public bool ValidateIndexFiles() 98 | { 99 | bool keepGoing = true; 100 | if (MainClass._gameDirectory != null) 101 | { 102 | string modlistPath = Path.Combine(MainClass._gameDirectory.FullName, "XivMods.json"); 103 | if (!File.Exists(modlistPath)) 104 | { 105 | ProblemChecker problemChecker = new ProblemChecker(MainClass._indexDirectory); 106 | var filesToCheck = new XivDataFile[] { XivDataFile._0A_Exd, XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui }; 107 | bool modifiedIndex = false; 108 | foreach (var file in filesToCheck) 109 | { 110 | var datCountCheck = problemChecker.CheckIndexDatCounts(file); 111 | datCountCheck.Wait(); 112 | if (datCountCheck.Result) 113 | { 114 | modifiedIndex = true; 115 | break; 116 | } 117 | } 118 | if (modifiedIndex) 119 | { 120 | main.PrintMessage("HERE BE DRAGONS\nPreviously modified game files found\nUse the originally used tool to start over, or reinstall the game before using this tool", 2); 121 | keepGoing = PromptContinuation(); 122 | } 123 | } 124 | else 125 | { 126 | var modData = JsonConvert.DeserializeObject(File.ReadAllText(modlistPath)); 127 | bool unsupportedSource = false; 128 | string unknownSource = ""; 129 | 130 | //List of acceptable mod sources 131 | //FFXIV_Modding_Tool is used by this tool 132 | //FilesAddedByTexTools is hardcoded in the framework and is used in certain situations 133 | //BLANK seems to be caused by a framework bug as well, so we allow it 134 | List acceptedSourcesList = new List{ "FFXIV_Modding_Tool", "FilesAddedByTexTools", "_INTERNAL_", "" }; 135 | foreach (Mod mod in modData.Mods) 136 | { 137 | if (!acceptedSourcesList.Contains(mod.source)) 138 | { 139 | unknownSource = mod.source; 140 | unsupportedSource = true; 141 | break; 142 | } 143 | } 144 | if (unsupportedSource) 145 | { 146 | main.PrintMessage($"Found a mod applied by an unknown application, game stability cannot be guaranteed: {unknownSource}", 3); 147 | keepGoing = PromptContinuation(); 148 | } 149 | } 150 | } 151 | return keepGoing; 152 | } 153 | 154 | public bool ValidateCache() 155 | { 156 | main.PrintMessage("Validating cache..."); 157 | if (MainClass._gameDirectory.GetFiles("mod_cache.db").Length == 0 || MainClass._gameDirectory.GetFiles("item_sets.db").Length == 0) 158 | return false; 159 | else if (new FileInfo(Path.Combine(MainClass._gameDirectory.FullName, "mod_cache.db")).Length == 0 || new FileInfo(Path.Combine(MainClass._gameDirectory.FullName, "item_sets.db")).Length == 0) 160 | return false; 161 | return true; 162 | } 163 | 164 | bool PromptContinuationReply(string answer, bool defaultanswer = false){ 165 | switch (answer.ToLower()) 166 | { 167 | case "y": 168 | return true; 169 | case "n": 170 | return false; 171 | case "\n": 172 | return defaultanswer; 173 | default: 174 | return false; 175 | } 176 | } 177 | 178 | public bool PromptContinuation(string message = "Would you like to continue?", bool defaultanswer = false) 179 | { 180 | string choicestring; 181 | if (!defaultanswer) 182 | choicestring = "y/N"; 183 | else if (defaultanswer) 184 | choicestring = "Y/n"; 185 | else 186 | choicestring = "y/n"; 187 | 188 | main.PrintMessage($"{message} ({choicestring})", 1); 189 | var answerKey = Console.ReadKey(); 190 | string answer = answerKey.KeyChar.ToString().ToLower(); 191 | if(answerKey.Key == ConsoleKey.Enter){ answer = "\n"; } 192 | Console.Write("\n"); 193 | return PromptContinuationReply(answer, defaultanswer); 194 | } 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /FFXIV_Modding_Tool/FirstTimeSetup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | using xivModdingFramework.Mods; 7 | using System.Collections.Generic; 8 | using FFXIV_Modding_Tool.Configuration; 9 | using FFXIV_Modding_Tool.Validation; 10 | 11 | namespace FFXIV_Modding_Tool.FirstTimeSetup 12 | { 13 | public class SetupCommand 14 | { 15 | public SetupCommand(){} 16 | Validators validation = new Validators(); 17 | MainClass main = new MainClass(); 18 | Config config = new Config(); 19 | 20 | static string _home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); 21 | 22 | //Lists of common install and profile locations to assist with the first-time setup. 23 | //Linux 24 | static List _InstallLocations_Linux = new List() { 25 | Path.Combine(_home, "Games", "final-fantasy-xiv-a-realm-reborn", "drive_c", "Program Files (x86)", "SquareEnix", "FINAL FANTASY XIV - A Realm Reborn"), 26 | Path.Combine(_home, "Games", "final-fantasy-xiv-online", "drive_c", "Program Files (x86)", "SquareEnix", "FINAL FANTASY XIV - A Realm Reborn"), 27 | Path.Combine(_home, ".steam", "steam", "steamapps", "common", "Final Fantasy XIV Online")}; 28 | static List _UserDataLocations_Linux = new List() { 29 | Path.Combine(_home, "Games", "final-fantasy-xiv-a-realm-reborn", "drive_c", "users", $"{Environment.UserName}", "My Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn"), 30 | Path.Combine(_home, "Games", "final-fantasy-xiv-online", "drive_c", "users", $"{Environment.UserName}", "My Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn"), 31 | Path.Combine(_home, "Games", "final-fantasy-xiv-a-realm-reborn", "drive_c", "users", $"{Environment.UserName}", "Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn"), 32 | Path.Combine(_home, "Games", "final-fantasy-xiv-online", "drive_c", "users", $"{Environment.UserName}", "Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn"), 33 | Path.Combine(_home, ".steam", "steam", "steamapps", "compatdata", "39210", "pfx", "drive_c", "users", "steamuser", "My Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn")}; 34 | //Mac 35 | static List _InstallLocations_Mac = new List() { 36 | Path.Combine(_home, "Library", "Application Support", "FINAL FANTASY XIV ONLINE", "Bottles", "published_Final_Fantasy", "drive_c", "Program Files (x86)", "SquareEnix", "FINAL FANTASY XIV - A Realm Reborn") 37 | }; 38 | static List _UserDataLocations_Mac = new List() { 39 | Path.Combine(_home, "My Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn") 40 | }; 41 | 42 | //Windows 43 | static List _InstallLocations_Windows = new List() { 44 | Path.Combine("C:\\", "Program Files (x86)", "SquareEnix", "FINAL FANTASY XIV - A Realm Reborn") 45 | }; 46 | static List _UserDataLocations_Windows = new List() { 47 | Path.Combine(_home, "My Documents", "My Games", "FINAL FANTASY XIV - A Realm Reborn") 48 | }; 49 | 50 | //Combining all lists to make itteration easy 51 | Dictionary> _InstallLocations = new Dictionary>() {["Linux"] = _InstallLocations_Linux, ["Mac"] = _InstallLocations_Mac, ["Windows"] = _InstallLocations_Windows}; 52 | Dictionary> _UserDataLocations = new Dictionary>(){["Linux"] = _UserDataLocations_Linux, ["Mac"] = _UserDataLocations_Mac, ["Windows"] = _UserDataLocations_Windows}; 53 | 54 | //Lists to store Valid locations 55 | List _ValidInstallLocations = new List() {}; 56 | List _ValidUserDataLocations = new List() {}; 57 | 58 | private string _OperatingSystemAsString(){ 59 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)){ 60 | return "Linux"; 61 | } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)){ 62 | return "Mac"; 63 | } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)){ 64 | return "Windows"; 65 | } else { 66 | return ""; 67 | } 68 | } 69 | 70 | private bool _ValidDirectory(string path, string type){ 71 | if (!string.IsNullOrEmpty(path)){ 72 | return validation.ValidateDirectory(new DirectoryInfo(path), type); 73 | } else { 74 | return false; 75 | } 76 | } 77 | 78 | private string AskForInstallationDirectory(){ 79 | main.PrintMessage("----------\nFirst we'll try to define your Game Directory!", 1); 80 | main.PrintMessage(@" Example locations: 81 | MacOS: /Users//Library/Application Support/FINAL FANTASY XIV ONLINE/Bottles/published_Final_Fantasy/drive_c/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn 82 | Linux: /path/to/WINEBOTTLE/drive_c/Program Files (x86)/SquareEnix/FINAL FANTASY XIV - A Realm Reborn 83 | Windows: C:\Program Files (x86)\SquareEnix\FINAL FANTASY XIV - A Realm Reborn 84 | "); 85 | 86 | if (_ValidInstallLocations.Count > 0){ 87 | main.PrintMessage($"Found {_ValidInstallLocations.Count} possible Game folder(s):"); 88 | foreach (string path in _ValidInstallLocations){ 89 | main.PrintMessage($"{path}"); 90 | } 91 | } else {main.PrintMessage("Found no valid game installs in common locations, you must define the Game Directory path on your own."); } 92 | string _GameDirectoryFromConsole = ""; 93 | while (!_ValidDirectory(Path.Combine(_GameDirectoryFromConsole, "game", "sqpack", "ffxiv"), "GameDirectory")){ 94 | Console.Write("\nEnter your Game Directory: "); 95 | _GameDirectoryFromConsole=@"" + Console.ReadLine().Replace("\"", "").Replace("~", _home); 96 | if(!_ValidDirectory(Path.Combine(_GameDirectoryFromConsole, "game", "sqpack", "ffxiv"), "GameDirectory")){ 97 | main.PrintMessage("Invalid directory, please confirm that it matches the examples provided.", 3); 98 | } 99 | } 100 | return _GameDirectoryFromConsole; 101 | } 102 | 103 | private string AskForConfigurationDirectory(){ 104 | main.PrintMessage("----------\nNow we'll have to find your Configuration directory!", 1); 105 | main.PrintMessage(@" Example locations: 106 | MacOS: /Users//My Documents/My Games/FINAL FANTASY XIV - A Realm Reborn 107 | Linux: /path/to/WINEBOTTLE/drive_c/users//My Documents/My Games/FINAL FANTASY XIV - A Realm Reborn 108 | Windows: C:\users\\My Documents\My Games\FINAL FANTASY XIV - A Realm Reborn 109 | "); 110 | 111 | if (_ValidUserDataLocations.Count > 0){ 112 | main.PrintMessage($"Found {_ValidUserDataLocations.Count} possible Configuration folder(s):"); 113 | foreach (string path in _ValidUserDataLocations){ 114 | main.PrintMessage($"{path}"); 115 | } 116 | } else { main.PrintMessage("Found no valid Configuration folders in common locations, you must define the Configuration Directory path on your own."); } 117 | string _ConfigDirectoryFromConsole = ""; 118 | while (!_ValidDirectory(_ConfigDirectoryFromConsole, "ConfigDirectory")){ 119 | Console.Write("\nEnter your Config Directory: "); 120 | _ConfigDirectoryFromConsole=@"" + Console.ReadLine().Replace("\"", "").Replace("~", _home); 121 | if(!_ValidDirectory(_ConfigDirectoryFromConsole, "ConfigDirectory")){ 122 | main.PrintMessage("Invalid directory, please confirm that it matches the examples provided.", 3); 123 | } 124 | } 125 | return _ConfigDirectoryFromConsole; 126 | } 127 | 128 | private string AskForBackupDirectory(){ 129 | main.PrintMessage("----------\nTime to set up your index backup directory.", 1); 130 | main.PrintMessage(@" Example locations: 131 | MacOS: /Users//My Documents/FFXIV Index Backups 132 | Linux: /home//FFXIV Index Backups 133 | Windows: C:\users\\My Documents\FFXIV Index Backups 134 | 135 | This folder can be anywhere but must already exist. 136 | "); 137 | 138 | string _BackupDirectoryFromConsole = ""; 139 | while (!_ValidDirectory(_BackupDirectoryFromConsole, "BackupDirectory")){ 140 | Console.Write("\nEnter your desired Backup Directory: "); 141 | _BackupDirectoryFromConsole=@"" + Console.ReadLine().Replace("\"", "").Replace("~", _home); 142 | if(!_ValidDirectory(_BackupDirectoryFromConsole, "BackupDirectory")){ 143 | main.PrintMessage("Invalid directory. Make sure it exists and is accessable.", 3); 144 | } 145 | } 146 | return _BackupDirectoryFromConsole; 147 | } 148 | 149 | public void ExecuteSetup(){ 150 | main.PrintMessage($"Starting configuration wizard for first-time setup...\nThis will overwrite the configuration file at {Config.configFile}\nYou'll be guided, step-by-step, to ensure that your configuration file is valid.\n\nWe'll start off by scanning common installation directories.", 1); 151 | if(!validation.PromptContinuation("Ready?", true)){ return; } 152 | if (!string.IsNullOrEmpty(_OperatingSystemAsString())){ 153 | foreach (string path in _InstallLocations[_OperatingSystemAsString()]){ 154 | if (_ValidDirectory(Path.Combine(path, "game", "sqpack", "ffxiv"), "GameDirectory")){ 155 | _ValidInstallLocations.Add(path); 156 | } 157 | } 158 | foreach (string path in _UserDataLocations[_OperatingSystemAsString()]){ 159 | if (_ValidDirectory(Path.Combine(path), "ConfigDirectory")){ 160 | _ValidUserDataLocations.Add(path); 161 | } 162 | } 163 | } 164 | string _GameDirectoryFromConsole = AskForInstallationDirectory(); 165 | string _ConfigDirectoryFromConsole = AskForConfigurationDirectory(); 166 | string _BackupDirectoryFromConsole = AskForBackupDirectory(); 167 | 168 | main.PrintMessage("----------\nFinal confirmation.", 1); 169 | main.PrintMessage($"Game Directory = {_GameDirectoryFromConsole}", 1); 170 | main.PrintMessage($"Config Directory = {_ConfigDirectoryFromConsole}", 1); 171 | main.PrintMessage($"Backup Directory = {_BackupDirectoryFromConsole}", 1); 172 | if(!validation.PromptContinuation("\nDoes the configuration look correct?", false)){ 173 | main.PrintMessage("Cancelled.", 3); 174 | return; 175 | } else { 176 | config.SaveConfig("GameDirectory", _GameDirectoryFromConsole); 177 | config.SaveConfig("ConfigDirectory", _ConfigDirectoryFromConsole); 178 | config.SaveConfig("BackupDirectory", _BackupDirectoryFromConsole); 179 | main.PrintMessage($"Configuration saved to {Config.configFile}", 1); 180 | } 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | FFXIV_TexTools_CLI/bin 3 | FFXIV_TexTools_CLI/obj 4 | FFXIV_Modding_Tool/bin 5 | FFXIV_Modding_Tool/obj 6 | .github 7 | testing 8 | FFXIV_Modding_Tool/references/xivModdingFramework.dll 9 | FFXIV_Modding_Tool/references/* 10 | !FFXIV_Modding_Tool/references/PresentationCore.dll 11 | 12 | 13 | # Created by https://www.gitignore.io/api/csharp,monodevelop,visualstudio 14 | # Edit at https://www.gitignore.io/?templates=csharp,monodevelop,visualstudio 15 | 16 | ### Csharp ### 17 | ## Ignore Visual Studio temporary files, build results, and 18 | ## files generated by popular Visuahttps://github.com/fosspill/FFXIV_Modding_Tool/blob/dotnet/.gitignorel Studio add-ons. 19 | ## 20 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 21 | 22 | # User-specific fileshttps://github.com/fosspill/FFXIV_Modding_Tool/blob/dotnet/.gitignore 23 | *.rsuser 24 | *.suo 25 | *.user 26 | *.userosscache 27 | *.sln.docstates 28 | 29 | # User-specific files (MonoDevelop/Xamarin Studio) 30 | *.userprefs 31 | 32 | # Mono auto generated files 33 | mono_crash.* 34 | 35 | # Build results 36 | [Dd]ebug/ 37 | [Dd]ebugPublic/ 38 | [Rr]elease/ 39 | [Rr]eleases/ 40 | x64/ 41 | x86/ 42 | [Aa][Rr][Mm]/ 43 | [Aa][Rr][Mm]64/ 44 | bld/ 45 | [Bb]in/ 46 | [Oo]bj/ 47 | [Ll]og/ 48 | 49 | # Visual Studio 2015/2017 cache/options directory 50 | .vs/ 51 | # Uncomment if you have tasks that create the project's static files in wwwroot 52 | #wwwroot/ 53 | 54 | # Visual Studio 2017 auto generated files 55 | Generated\ Files/ 56 | 57 | # MSTest test Results 58 | [Tt]est[Rr]esult*/ 59 | [Bb]uild[Ll]og.* 60 | 61 | # NUNIT 62 | *.VisualState.xml 63 | TestResult.xml 64 | 65 | # Build Results of an ATL Project 66 | [Dd]ebugPS/ 67 | [Rr]eleasePS/ 68 | dlldata.c 69 | 70 | # Benchmark Results 71 | BenchmarkDotNet.Artifacts/ 72 | 73 | # .NET Core 74 | project.lock.json 75 | project.fragment.lock.json 76 | artifacts/ 77 | 78 | # StyleCop 79 | StyleCopReport.xml 80 | 81 | # Files built by Visual Studio 82 | *_i.c 83 | *_p.c 84 | *_h.h 85 | *.ilk 86 | *.meta 87 | *.obj 88 | *.iobj 89 | *.pch 90 | *.pdb 91 | *.ipdb 92 | *.pgc 93 | *.pgd 94 | *.rsp 95 | *.sbr 96 | *.tlb 97 | *.tli 98 | *.tlh 99 | *.tmp 100 | *.tmp_proj 101 | *_wpftmp.csproj 102 | *.log 103 | *.vspscc 104 | *.vssscc 105 | .builds 106 | *.pidb 107 | *.svclog 108 | *.scc 109 | 110 | # Chutzpah Test files 111 | _Chutzpah* 112 | 113 | # Visual C++ cache files 114 | ipch/ 115 | *.aps 116 | *.ncb 117 | *.opendb 118 | *.opensdf 119 | *.sdf 120 | *.cachefile 121 | *.VC.db 122 | *.VC.VC.opendb 123 | 124 | # Visual Studio profiler 125 | *.psess 126 | *.vsp 127 | *.vspx 128 | *.sap 129 | 130 | # Visual Studio Trace Files 131 | *.e2e 132 | 133 | # TFS 2012 Local Workspace 134 | $tf/ 135 | 136 | # Guidance Automation Toolkit 137 | *.gpState 138 | 139 | # ReSharper is a .NET coding add-in 140 | _ReSharper*/ 141 | *.[Rr]e[Ss]harper 142 | *.DotSettings.user 143 | 144 | # JustCode is a .NET coding add-in 145 | .JustCode 146 | 147 | # TeamCity is a build add-in 148 | _TeamCity* 149 | 150 | # DotCover is a Code Coverage Tool 151 | *.dotCover 152 | 153 | # AxoCover is a Code Coverage Tool 154 | .axoCover/* 155 | !.axoCover/settings.json 156 | 157 | # Visual Studio code coverage results 158 | *.coverage 159 | *.coveragexml 160 | 161 | # NCrunch 162 | _NCrunch_* 163 | .*crunch*.local.xml 164 | nCrunchTemp_* 165 | 166 | # MightyMoose 167 | *.mm.* 168 | AutoTest.Net/ 169 | 170 | # Web workbench (sass) 171 | .sass-cache/ 172 | 173 | # Installshield output folder 174 | [Ee]xpress/ 175 | 176 | # DocProject is a documentation generator add-in 177 | DocProject/buildhelp/ 178 | DocProject/Help/*.HxT 179 | DocProject/Help/*.HxC 180 | DocProject/Help/*.hhc 181 | DocProject/Help/*.hhk 182 | DocProject/Help/*.hhp 183 | DocProject/Help/Html2 184 | DocProject/Help/html 185 | 186 | # Click-Once directory 187 | publish/ 188 | 189 | # Publish Web Output 190 | *.[Pp]ublish.xml 191 | *.azurePubxml 192 | # Note: Comment the next line if you want to checkin your web deploy settings, 193 | # but database connection strings (with potential passwords) will be unencrypted 194 | *.pubxml 195 | *.publishproj 196 | 197 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 198 | # checkin your Azure Web App publish settings, but sensitive information contained 199 | # in these scripts will be unencrypted 200 | PublishScripts/ 201 | 202 | # NuGet Packages 203 | *.nupkg 204 | # The packages folder can be ignored because of Package Restore 205 | **/[Pp]ackages/* 206 | # except build/, which is used as an MSBuild target. 207 | !**/[Pp]ackages/build/ 208 | # Uncomment if necessary however generally it will be regenerated when needed 209 | #!**/[Pp]ackages/repositories.config 210 | # NuGet v3's project.json files produces more ignorable files 211 | *.nuget.props 212 | *.nuget.targets 213 | 214 | # Microsoft Azure Build Output 215 | csx/ 216 | *.build.csdef 217 | 218 | # Microsoft Azure Emulator 219 | ecf/ 220 | rcf/ 221 | 222 | # Windows Store app package directories and files 223 | AppPackages/ 224 | BundleArtifacts/ 225 | Package.StoreAssociation.xml 226 | _pkginfo.txt 227 | *.appx 228 | *.appxbundle 229 | *.appxupload 230 | 231 | # Visual Studio cache files 232 | # files ending in .cache can be ignored 233 | *.[Cc]ache 234 | # but keep track of directories ending in .cache 235 | !?*.[Cc]ache/ 236 | 237 | # Others 238 | ClientBin/ 239 | ~$* 240 | *~ 241 | *.dbmdl 242 | *.dbproj.schemaview 243 | *.jfm 244 | *.pfx 245 | *.publishsettings 246 | orleans.codegen.cs 247 | 248 | # Including strong name files can present a security risk 249 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 250 | #*.snk 251 | 252 | # Since there are multiple workflows, uncomment next line to ignore bower_components 253 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 254 | #bower_components/ 255 | 256 | # RIA/Silverlight projects 257 | Generated_Code/ 258 | 259 | # Backup & report files from converting an old project file 260 | # to a newer Visual Studio version. Backup files are not needed, 261 | # because we have git ;-) 262 | _UpgradeReport_Files/ 263 | Backup*/ 264 | UpgradeLog*.XML 265 | UpgradeLog*.htm 266 | ServiceFabricBackup/ 267 | *.rptproj.bak 268 | 269 | # SQL Server files 270 | *.mdf 271 | *.ldf 272 | *.ndf 273 | 274 | # Business Intelligence projects 275 | *.rdl.data 276 | *.bim.layout 277 | *.bim_*.settings 278 | *.rptproj.rsuser 279 | *- Backup*.rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | ### MonoDevelop ### 363 | #User Specific 364 | *.usertasks 365 | 366 | #Mono Project Files 367 | *.resources 368 | test-results/ 369 | 370 | ### VisualStudio ### 371 | 372 | # User-specific files 373 | 374 | # User-specific files (MonoDevelop/Xamarin Studio) 375 | 376 | # Mono auto generated files 377 | 378 | # Build results 379 | 380 | # Visual Studio 2015/2017 cache/options directory 381 | # Uncomment if you have tasks that create the project's static files in wwwroot 382 | 383 | # Visual Studio 2017 auto generated files 384 | 385 | # MSTest test Results 386 | 387 | # NUNIT 388 | 389 | # Build Results of an ATL Project 390 | 391 | # Benchmark Results 392 | 393 | # .NET Core 394 | 395 | # StyleCop 396 | 397 | # Files built by Visual Studio 398 | 399 | # Chutzpah Test files 400 | 401 | # Visual C++ cache files 402 | 403 | # Visual Studio profiler 404 | 405 | # Visual Studio Trace Files 406 | 407 | # TFS 2012 Local Workspace 408 | 409 | # Guidance Automation Toolkit 410 | 411 | # ReSharper is a .NET coding add-in 412 | 413 | # JustCode is a .NET coding add-in 414 | 415 | # TeamCity is a build add-in 416 | 417 | # DotCover is a Code Coverage Tool 418 | 419 | # AxoCover is a Code Coverage Tool 420 | 421 | # Visual Studio code coverage results 422 | 423 | # NCrunch 424 | 425 | # MightyMoose 426 | 427 | # Web workbench (sass) 428 | 429 | # Installshield output folder 430 | 431 | # DocProject is a documentation generator add-in 432 | 433 | # Click-Once directory 434 | 435 | # Publish Web Output 436 | # Note: Comment the next line if you want to checkin your web deploy settings, 437 | # but database connection strings (with potential passwords) will be unencrypted 438 | 439 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 440 | # checkin your Azure Web App publish settings, but sensitive information contained 441 | # in these scripts will be unencrypted 442 | 443 | # NuGet Packages 444 | # The packages folder can be ignored because of Package Restore 445 | # except build/, which is used as an MSBuild target. 446 | # Uncomment if necessary however generally it will be regenerated when needed 447 | # NuGet v3's project.json files produces more ignorable files 448 | 449 | # Microsoft Azure Build Output 450 | 451 | # Microsoft Azure Emulator 452 | 453 | # Windows Store app package directories and files 454 | 455 | # Visual Studio cache files 456 | # files ending in .cache can be ignored 457 | # but keep track of directories ending in .cache 458 | 459 | # Others 460 | 461 | # Including strong name files can present a security risk 462 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 463 | 464 | # Since there are multiple workflows, uncomment next line to ignore bower_components 465 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 466 | 467 | # RIA/Silverlight projects 468 | 469 | # Backup & report files from converting an old project file 470 | # to a newer Visual Studio version. Backup files are not needed, 471 | # because we have git ;-) 472 | 473 | # SQL Server files 474 | 475 | # Business Intelligence projects 476 | 477 | # Microsoft Fakes 478 | 479 | # GhostDoc plugin setting file 480 | 481 | # Node.js Tools for Visual Studio 482 | 483 | # Visual Studio 6 build log 484 | 485 | # Visual Studio 6 workspace options file 486 | 487 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 488 | 489 | # Visual Studio LightSwitch build output 490 | 491 | # Paket dependency manager 492 | 493 | # FAKE - F# Make 494 | 495 | # CodeRush personal settings 496 | 497 | # Python Tools for Visual Studio (PTVS) 498 | 499 | # Cake - Uncomment if you are using it 500 | # tools/** 501 | # !tools/packages.config 502 | 503 | # Tabs Studio 504 | 505 | # Telerik's JustMock configuration file 506 | 507 | # BizTalk build output 508 | 509 | # OpenCover UI analysis results 510 | 511 | # Azure Stream Analytics local run output 512 | 513 | # MSBuild Binary and Structured Log 514 | 515 | # NVidia Nsight GPU debugger configuration file 516 | 517 | # MFractors (Xamarin productivity tool) working folder 518 | 519 | # Local History for Visual Studio 520 | 521 | # BeatPulse healthcheck temp database 522 | 523 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 524 | 525 | # End of https://www.gitignore.io/api/csharp,monodevelop,visualstudio 526 | -------------------------------------------------------------------------------- /FFXIV_Modding_Tool/Arguments.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Reflection; 5 | using xivModdingFramework.Cache; 6 | using xivModdingFramework.General.Enums; 7 | using System.Collections.Generic; 8 | using FFXIV_Modding_Tool.Configuration; 9 | using FFXIV_Modding_Tool.Validation; 10 | using FFXIV_Modding_Tool.FirstTimeSetup; 11 | 12 | namespace FFXIV_Modding_Tool.Commandline 13 | { 14 | public class Arguments 15 | { 16 | public Arguments(){} 17 | MainClass main = new MainClass(); 18 | Config config = new Config(); 19 | Validators validation = new Validators(); 20 | SetupCommand setup = new SetupCommand(); 21 | List ttmpPaths = new List(); 22 | DirectoryInfo outputFile = new DirectoryInfo("/tmp/placeholder.ttmp"); 23 | bool useWizard = false; 24 | bool importAll = false; 25 | bool skipProblemCheck = false; 26 | Dictionary> fullActions = new Dictionary>(); 27 | Dictionary actionAliases = new Dictionary(); 28 | Dictionary, Action> argumentsDict = new Dictionary, Action>(); 29 | string requestedAction; 30 | 31 | public void ArgumentHandler(string[] args) 32 | { 33 | if (!File.Exists(Config.configFile) || string.IsNullOrEmpty(File.ReadAllText(Config.configFile))) 34 | config.CreateDefaultConfig(); 35 | if (args.Length == 0) 36 | { 37 | SendHelpText(); 38 | return; 39 | } 40 | SetupDicts(); 41 | ReadArguments(args); 42 | } 43 | 44 | public void SetupDicts() 45 | { 46 | fullActions = new Dictionary>{ 47 | {"mods", new Dictionary{ 48 | {"refresh", new Action(() => { main.SetModActiveStates(); })}, 49 | {"enable", new Action(() => { main.ToggleModStates(true); })}, 50 | {"disable", new Action(() => { main.ToggleModStates(false); })}}}, 51 | {"modpack", new Dictionary{ 52 | {"import", new Action(() => { 53 | if (useWizard && importAll) 54 | { 55 | main.PrintMessage("You can't use the import wizard and skip the wizard at the same time", 3); 56 | useWizard = false; 57 | importAll = false; 58 | } 59 | main.ImportModpackHandler(ttmpPaths, useWizard, importAll, skipProblemCheck); })}, 60 | {"info", new Action(() => { main.GetModpackInfo(ttmpPaths); })}, 61 | {"create", new Action(() => { main.CreateModpack(outputFile); })}, 62 | }}, 63 | {"backup", new Dictionary{ 64 | {"", new Action(() => { main.BackupIndexes(); })} 65 | }}, 66 | {"reset", new Dictionary{ 67 | {"", new Action(() => { main.ResetMods(); })} 68 | }}, 69 | {"problemcheck", new Dictionary{ 70 | {"", new Action(() => { main.ProblemChecker(); })} 71 | }}, 72 | {"version", new Dictionary{ 73 | {"", new Action(() => { if (MainClass._gameDirectory == null) 74 | MainClass._gameDirectory = new DirectoryInfo(Path.Combine(config.ReadConfig("GameDirectory"), "game")); 75 | main.CheckVersions(); })} 76 | }}, 77 | {"help", new Dictionary{ 78 | {"", new Action(() => { SendHelpText(); })} 79 | }}, 80 | {"setup", new Dictionary{ 81 | {"", new Action(() => { setup.ExecuteSetup(); })} 82 | }}, 83 | // Defragmentation is broken in its current state, removing ability to use it 84 | // {"defragment", new Dictionary{ 85 | // {"", new Action(() => { main.ReclaimSpace(); })} 86 | // }}, 87 | }; 88 | actionAliases = new Dictionary{ 89 | {"mpi", "modpack import"}, 90 | {"mpinfo", "modpack info"}, 91 | {"mpc", "modpack create"}, 92 | {"mr", "mods refresh"}, 93 | {"me", "mods enable"}, 94 | {"md", "mods disable"}, 95 | {"b", "backup"}, 96 | {"r", "reset"}, 97 | {"pc", "problemcheck"}, 98 | {"v", "version"}, 99 | {"h", "help"}, 100 | {"s", "setup"}, 101 | // {"d", "defragment"} 102 | }; 103 | argumentsDict = new Dictionary, Action>{ 104 | {new List{"-g", "--gamedirectory"}, new Action((extraArg) => { MainClass._gameDirectory = new DirectoryInfo(Path.Combine(extraArg, "game")); 105 | MainClass._indexDirectory = new DirectoryInfo(Path.Combine(extraArg, "game", "sqpack", "ffxiv")); })}, 106 | {new List{"-c", "--configdirectory"}, new Action((extraArg) => { MainClass._configDirectory = new DirectoryInfo(extraArg); })}, 107 | {new List{"-b", "--backupdirectory"}, new Action((extraArg) => { MainClass._backupDirectory = new DirectoryInfo(extraArg); })}, 108 | {new List{"-t", "--ttmp"}, new Action((extraArg) => { ttmpPaths.Add(new DirectoryInfo(extraArg)); })}, 109 | {new List{"-w", "--wizard"}, new Action((extraArg) => { useWizard = true; })}, 110 | {new List{"-a", "--all"}, new Action((extraArg) => { importAll = true; })}, 111 | {new List{"-npc", "--noproblemcheck"}, new Action((extraArg) => { skipProblemCheck = true; })}, 112 | {new List{"-v", "--version"}, new Action((extraArg) => { requestedAction = "version"; })}, 113 | {new List{"-o", "--output"}, new Action((extraArg) => { outputFile = new DirectoryInfo(extraArg); })}, 114 | {new List{"-h", "--help"}, new Action((extraArg) => { requestedAction = "help"; })} 115 | }; 116 | } 117 | 118 | public void ReadArguments(string[] args) 119 | { 120 | if (fullActions.ContainsKey(args[0])) 121 | { 122 | if (args.Length > 1 && fullActions[args[0]].Keys.Contains(args[1])) 123 | { 124 | requestedAction = $"{args[0]} {args[1]}"; 125 | args = args.Skip(2).ToArray(); 126 | } 127 | else 128 | { 129 | requestedAction = args[0]; 130 | args = args.Skip(1).ToArray(); 131 | } 132 | } 133 | else if (actionAliases.ContainsKey(args[0])) 134 | { 135 | requestedAction = actionAliases[args[0]]; 136 | args = args.Skip(1).ToArray(); 137 | } 138 | else 139 | requestedAction = null; 140 | ProcessArguments(args); 141 | // Execute this last, after all the arguments are dealt with 142 | if (string.IsNullOrEmpty(requestedAction)) 143 | main.PrintMessage($"{args[0]} is not a valid action", 2); 144 | if (ActionRequirementsChecker(requestedAction)) 145 | { 146 | string[] requestedActionSplit = requestedAction.Split(' '); 147 | if (requestedActionSplit.Length > 1) 148 | fullActions[requestedActionSplit[0]][requestedActionSplit[1]](); 149 | else 150 | fullActions[requestedActionSplit[0]][""](); 151 | } 152 | } 153 | 154 | void ProcessArguments(string[] args) 155 | { 156 | List requiresPair = new List{ "-t", "--ttmp", "-g", "--gamedirectory", "-b", "--backupdirectory", "-c", "--configdirectory", "-o", "--output" }; 157 | foreach (var (cmdArg, cmdIndex) in args.Select((value, i) => (value, i))) 158 | { 159 | if (cmdArg.StartsWith("-")) 160 | { 161 | string nextArg; 162 | //The argument parsed needs a pair. Ex: "-t ttmp.ttmp" 163 | if (requiresPair.Contains(cmdArg)) 164 | { 165 | //To be removed: Deprecation warning! 166 | if (new List{ "-t", "--ttmp" }.Contains(cmdArg)) 167 | main.PrintMessage("-t and --ttmp will be deprecated and replaced with free-standing paths. Ex: ffmt mpi path/to/modpack.ttmp", 3); 168 | if (cmdIndex < args.Length - 1) 169 | nextArg = args[cmdIndex+1]; 170 | else 171 | nextArg = null; 172 | if (string.IsNullOrEmpty(nextArg) || nextArg.StartsWith("-")) 173 | main.PrintMessage($"{cmdArg} is missing an argument", 2); 174 | } 175 | else 176 | nextArg = null; 177 | foreach(List argumentList in argumentsDict.Keys) 178 | { 179 | if (argumentList.Contains(cmdArg)) 180 | { 181 | argumentsDict[argumentList](nextArg); 182 | break; 183 | } 184 | } 185 | } 186 | //The statement isn't first in the argument list and isn't required by a previous argument 187 | //Or it is the first... Assume these are TTMP files 188 | else if ((cmdIndex == 0 || (cmdIndex > 0 && !requiresPair.Contains(args[cmdIndex-1])))) 189 | { 190 | ttmpPaths.Add(new DirectoryInfo(cmdArg)); 191 | } 192 | } 193 | } 194 | 195 | public bool ActionRequirementsChecker(string requestedAction) 196 | { 197 | List requiresGameDirectory = new List { "modpack import", "modpack create", "mods refresh", "mods enable", "mods disable", "backup", "reset", "problemcheck"/*, "defragment"*/ }; 198 | List requiresBackupDirectory = new List { "modpack import", "mods refresh", "mods enable", "mods disable", "backup", "reset", "problemcheck" }; 199 | List requiresConfigDirectory = new List { "modpack import", "problemcheck" }; 200 | List requiresUpdatedBackups = new List { "modpack import", "mods refresh", "mods enable", "mods disable", "reset" }; 201 | List requiresValidIndexes = new List { "modpack import", "backup" }; 202 | List requiresTTMPFile = new List { "modpack import", "modpack info" }; 203 | 204 | if (requiresGameDirectory.Contains(requestedAction)) 205 | { 206 | if (!CheckGameDirectory()) 207 | return false; 208 | } 209 | if (requiresBackupDirectory.Contains(requestedAction)) 210 | { 211 | if (!CheckBackupDirectory()) 212 | return false; 213 | } 214 | if (requiresConfigDirectory.Contains(requestedAction)) 215 | { 216 | if (!CheckConfigDirectory()) 217 | return false; 218 | } 219 | if (requiresUpdatedBackups.Contains(requestedAction)) 220 | { 221 | if (!validation.ValidateBackups()) 222 | return false; 223 | } 224 | if (requiresValidIndexes.Contains(requestedAction)) 225 | { 226 | if (!validation.ValidateIndexFiles()) 227 | return false; 228 | } 229 | if (requiresTTMPFile.Contains(requestedAction)) 230 | { 231 | if (!CheckTTMPFile()) 232 | return false; 233 | } 234 | return true; 235 | } 236 | 237 | bool CheckGameDirectory() 238 | { 239 | if (MainClass._indexDirectory == null) 240 | { 241 | string configGameDirectory = config.ReadConfig("GameDirectory"); 242 | MainClass._gameDirectory = new DirectoryInfo(Path.Combine(configGameDirectory, "game")); 243 | MainClass._indexDirectory = new DirectoryInfo(Path.Combine(configGameDirectory, "game", "sqpack", "ffxiv")); 244 | } 245 | if (MainClass._indexDirectory == null || !validation.ValidateDirectory(MainClass._indexDirectory, "GameDirectory")) 246 | { 247 | main.PrintMessage("Invalid game directory", 2); 248 | return false; 249 | } 250 | if (!validation.ValidateCache()) 251 | { 252 | File.Delete(Path.Combine(MainClass._gameDirectory.FullName, "mod_cache.db")); 253 | File.Delete(Path.Combine(MainClass._gameDirectory.FullName, "item_sets.db")); 254 | } 255 | XivCache.SetGameInfo(MainClass._indexDirectory, XivLanguage.English); 256 | XivCache.CacheWorkerEnabled = false; 257 | return true; 258 | } 259 | 260 | bool CheckBackupDirectory() 261 | { 262 | if (MainClass._backupDirectory == null) 263 | MainClass._backupDirectory = new DirectoryInfo(config.ReadConfig("BackupDirectory")); 264 | if (MainClass._backupDirectory == null || !validation.ValidateDirectory(MainClass._backupDirectory, "BackupDirectory")) 265 | { 266 | main.PrintMessage("Invalid backup directory", 2); 267 | return false; 268 | } 269 | return true; 270 | } 271 | 272 | bool CheckConfigDirectory() 273 | { 274 | if (MainClass._configDirectory == null) 275 | MainClass._configDirectory = new DirectoryInfo(config.ReadConfig("ConfigDirectory")); 276 | if (MainClass._configDirectory == null || !validation.ValidateDirectory(MainClass._configDirectory, "ConfigDirectory")) 277 | { 278 | main.PrintMessage("Invalid game config directory", 2); 279 | return false; 280 | } 281 | return true; 282 | } 283 | 284 | bool CheckTTMPFile() 285 | { 286 | if (!ttmpPaths.Any()) 287 | { 288 | main.PrintMessage("Can't import without a modpack to import. At least 1 must be specificed. Ex: path/to/modpack.ttmp", 2); 289 | return false; 290 | } 291 | foreach (DirectoryInfo ttmp in ttmpPaths) 292 | { 293 | if (!validation.ValidateTTMPFile(ttmp.FullName)) 294 | { 295 | main.PrintMessage($"{ttmp.FullName} is an invalid ttmp file", 2); 296 | return false; 297 | } 298 | } 299 | return true; 300 | } 301 | 302 | public void SendHelpText() 303 | { 304 | string helpText = $@"Usage: {Assembly.GetEntryAssembly().GetName().Name} [action] {"{arguments}"} 305 | 306 | Available actions: 307 | modpack import, mpi Import a modpack, requires a .ttmp(2) to be specified 308 | modpack info, mpinfo Show info about a modpack, requires a .ttmp(2) to be specified 309 | modpack create, mpc Create a modpack out of your currently active mods 310 | mods enable, me Enable all installed mods 311 | mods disable, md Disable all installed mods 312 | mods refresh, mr Enable/disable mods as specified in modlist.cfg 313 | backup, b Backup clean index files for use in resetting the game 314 | reset, r Reset game to clean state 315 | problemcheck, pc Check if there are any problems with the game, mod or backup files 316 | version, v Display current application and game version 317 | help, h Display this text 318 | setup, s Run First-time Setup Wizard 319 | 320 | Available arguments: 321 | -g, --gamedirectory Full path to game install, including 'FINAL FANTASY XIV - A Realm Reborn' 322 | -c, --configdirectory Full path to directory where FFXIV.cfg and character data is saved, including 'FINAL FANTASY XIV - A Realm Reborn' 323 | -b, --backupdirectory Full path to directory with your index backups 324 | -t, --ttmp Will be deprecated - Full path to .ttmp(2) file (modpack import/info only) 325 | -w, --wizard Use the modpack wizard to select what mods to import (modpack import only) 326 | -a, --all Import all mods in a modpack immediately (modpack import only) 327 | -npc, --noproblemcheck Skip the problem check after importing a modpack 328 | -o, --output Path and filename to save .ttmp2 during Modpack Creation 329 | -v, --version Display current application and game version 330 | -h, --help Display this text 331 | path/to/modpack.ttmp Full path to modpack(s). Imports in the order given."; 332 | main.PrintMessage(helpText); 333 | } 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /FFXIV_Modding_Tool/Program.cs: -------------------------------------------------------------------------------- 1 | // Copyright © 2019 Ole Erik Brennhagen - All Rights Reserved 2 | // Copyright © 2019 Ivanka Heins - All Rights Reserved 3 | // 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | // 17 | // Credit to the TexTools UI contributors for inspiring and 18 | // influencing a lot of the code. 19 | // They can be found here: 20 | 21 | using System; 22 | using System.IO; 23 | using System.IO.Compression; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Threading.Tasks; 27 | using System.Reflection; 28 | using System.Runtime.InteropServices; 29 | using System.Text.RegularExpressions; 30 | using xivModdingFramework.General.Enums; 31 | using xivModdingFramework.Mods; 32 | using xivModdingFramework.Mods.DataContainers; 33 | using xivModdingFramework.Helpers; 34 | using xivModdingFramework.Mods.FileTypes; 35 | using xivModdingFramework.SqPack.FileTypes; 36 | using xivModdingFramework.Textures.Enums; 37 | using FFXIV_Modding_Tool.Configuration; 38 | using FFXIV_Modding_Tool.Commandline; 39 | using FFXIV_Modding_Tool.Validation; 40 | using Newtonsoft.Json; 41 | 42 | namespace FFXIV_Modding_Tool 43 | { 44 | public class MainClass 45 | { 46 | public static DirectoryInfo _gameDirectory; 47 | public static DirectoryInfo _indexDirectory; 48 | public static DirectoryInfo _backupDirectory; 49 | public static DirectoryInfo _configDirectory; 50 | public static DirectoryInfo _modpackDirectory; 51 | public static DirectoryInfo _projectconfDirectory; 52 | public static string modActiveConfFile; 53 | private bool importStarted; 54 | 55 | public class ModActiveStatus 56 | { 57 | MainClass main = new MainClass(); 58 | public string modpack { get; set; } 59 | public string name { get; set; } 60 | public string map { get; set; } 61 | public string part { get; set; } 62 | public string race { get; set; } 63 | public string file { get; set; } 64 | public bool enabled { get; set; } 65 | 66 | public ModActiveStatus() { } 67 | 68 | public ModActiveStatus(ModsJson entry) 69 | { 70 | modpack = entry.ModPackEntry.name; 71 | name = entry.Name; 72 | file = entry.FullPath; 73 | map = main.GetMap(file); 74 | part = main.GetType(file); 75 | race = main.GetRace(file).ToString(); 76 | enabled = true; 77 | } 78 | } 79 | public ModActiveStatus modpackActiveStatus; 80 | 81 | /* Print slightly nicer messages. Can add logging here as well if needed. 82 | 1 = Success message, 2 = Error message, 3 = Warning message 83 | */ 84 | public void PrintMessage(string message, int importance = 0) 85 | { 86 | Console.ResetColor(); 87 | switch (importance) 88 | { 89 | case 1: 90 | Console.ForegroundColor = ConsoleColor.Green; 91 | goto default; 92 | case 2: 93 | Console.Write("ERROR: "); 94 | Console.ForegroundColor = ConsoleColor.Red; 95 | Console.WriteLine(message); 96 | Console.ResetColor(); 97 | Environment.Exit(1); 98 | break; 99 | case 3: 100 | Console.Write("WARNING: "); 101 | Console.ForegroundColor = ConsoleColor.Yellow; 102 | goto default; 103 | default: 104 | Console.WriteLine(message); 105 | Console.ResetColor(); 106 | break; 107 | } 108 | } 109 | 110 | public void CheckVersions() 111 | { 112 | string ffxivVersion = "not detected"; 113 | if (_gameDirectory != null) 114 | { 115 | var versionFile = Path.Combine(_gameDirectory.FullName, "ffxivgame.ver"); 116 | if (File.Exists(versionFile) && File.ReadAllText(versionFile).Length > 0) 117 | { 118 | var versionData = File.ReadAllLines(versionFile); 119 | ffxivVersion = new Version(versionData[0].Substring(0, versionData[0].LastIndexOf("."))).ToString(); 120 | } 121 | } 122 | Version version = Assembly.GetEntryAssembly().GetName().Version; 123 | PrintMessage($"{Assembly.GetExecutingAssembly().GetCustomAttribute().Title} {version}\nGame version {ffxivVersion}"); 124 | } 125 | 126 | public void GetModpackInfo(List ttmpPaths) 127 | { 128 | foreach (DirectoryInfo ttmpPath in ttmpPaths) 129 | { 130 | Dictionary modpackInfo = new Dictionary 131 | { 132 | ["name"] = Path.GetFileNameWithoutExtension(ttmpPath.FullName), 133 | ["type"] = "Simple", 134 | ["author"] = "N/A", 135 | ["version"] = "N/A", 136 | ["description"] = "N/A", 137 | ["modAmount"] = "0" 138 | }; 139 | if (ttmpPath.Extension == ".ttmp2") 140 | { 141 | var ttmp = new TTMP(ttmpPath, "FFXIV_Modding_Tool"); 142 | var ttmpData = ttmp.GetModPackJsonData(ttmpPath); 143 | ttmpData.Wait(); 144 | var ttmpInfo = ttmpData.Result.ModPackJson; 145 | modpackInfo["name"] = ttmpInfo.Name; 146 | if (ttmpInfo.TTMPVersion.Contains("w")) 147 | { 148 | modpackInfo["type"] = "Wizard"; 149 | modpackInfo["description"] = ttmpInfo.Description; 150 | int modCount = 0; 151 | foreach (var page in ttmpInfo.ModPackPages) 152 | { 153 | foreach (var group in page.ModGroups) 154 | modCount += group.OptionList.Count; 155 | } 156 | modpackInfo["modAmount"] = modCount.ToString(); 157 | } 158 | else 159 | modpackInfo["modAmount"] = ttmpInfo.SimpleModsList.Count.ToString(); 160 | modpackInfo["author"] = ttmpInfo.Author; 161 | modpackInfo["version"] = ttmpInfo.Version; 162 | } 163 | else if (ttmpPath.Extension == ".ttmp") 164 | modpackInfo["modAmount"] = GetOldModpackJson(ttmpPath).Count.ToString(); 165 | PrintMessage($@"Name: {modpackInfo["name"]} 166 | Type: {modpackInfo["type"]} 167 | Author: {modpackInfo["author"]} 168 | Version: {modpackInfo["version"]} 169 | Description: {modpackInfo["description"]} 170 | Number of mods: {modpackInfo["modAmount"]} 171 | "); 172 | } 173 | } 174 | 175 | public bool IndexLocked() 176 | { 177 | var index = new xivModdingFramework.SqPack.FileTypes.Index(_indexDirectory); 178 | bool indexLocked = index.IsIndexLocked(XivDataFile._0A_Exd); 179 | return indexLocked; 180 | } 181 | 182 | #region Importing Functions 183 | public void ImportModpackHandler(List ttmpPaths, bool useWizard, bool importAll, bool skipProblemCheck) 184 | { 185 | try 186 | { 187 | if (IndexLocked()) 188 | { 189 | PrintMessage("Unable to import while the game is running.", 2); 190 | return; 191 | } 192 | } 193 | catch (Exception ex) 194 | { 195 | PrintMessage($"Problem reading index files:\n{ex.Message}", 2); 196 | } 197 | PrintMessage("Starting import..."); 198 | try 199 | { 200 | ModpackDataHandler(ttmpPaths, useWizard, importAll); 201 | } 202 | catch (Exception ex) 203 | { 204 | PrintMessage($"There was an error importing a modpack.\nMessage: {ex.Message}", 2); 205 | } 206 | if (!skipProblemCheck) 207 | ProblemChecker(); 208 | return; 209 | } 210 | 211 | void ModpackDataHandler(List ttmpPaths, bool useWizard, bool importAll) 212 | { 213 | Dictionary> ttmpDataLists = new Dictionary>(); 214 | foreach(DirectoryInfo ttmpPath in ttmpPaths) 215 | { 216 | var ttmp = new TTMP(ttmpPath, "FFXIV_Modding_Tool"); 217 | ModPackJson ttmpData = null; 218 | string ttmpName = null; 219 | List ttmpDataList = new List(); 220 | PrintMessage($"Extracting data from {ttmpPath.Name}..."); 221 | if (ttmpPath.Extension == ".ttmp2") 222 | { 223 | var _ttmpData = ttmp.GetModPackJsonData(ttmpPath); 224 | _ttmpData.Wait(); 225 | ttmpData = _ttmpData.Result.ModPackJson; 226 | } 227 | if (ttmpData != null) 228 | { 229 | ttmpName = ttmpData.Name; 230 | if (ttmpData.TTMPVersion.Contains("w")) 231 | { 232 | PrintMessage("Starting wizard..."); 233 | ttmpDataList = TTMP2DataList(WizardDataHandler(ttmpData), ttmpData, false, true); 234 | } 235 | else 236 | ttmpDataList = TTMP2DataList(ttmpData.SimpleModsList, ttmpData, useWizard, importAll); 237 | } 238 | else 239 | { 240 | ttmpName = Path.GetFileNameWithoutExtension(ttmpPath.FullName); 241 | ttmpDataList = TTMPDataList(ttmpPath, useWizard, importAll); 242 | } 243 | ttmpDataLists[ttmpPath] = ttmpDataList; 244 | } 245 | 246 | var _totalMods = ttmpDataLists.Sum(x => x.Value.Count); 247 | PrintMessage($"Data extraction successful."); 248 | var _currentModpackNum = 1; 249 | foreach(var ttmpDataList in ttmpDataLists) 250 | { 251 | TTMP _textoolsModpack = new TTMP(ttmpDataList.Key, "FFXIV_Modding_Tool"); 252 | int originalModCount = ttmpDataList.Value.Count; 253 | List modActiveStates = UpdateActiveModsConfFile(ttmpDataList.Value); 254 | PrintMessage($"Importing {ttmpDataList.Value.Count}/{originalModCount} mods from {ttmpDataList.Value[0].ModPackEntry.name} (Modpack {_currentModpackNum}/{ttmpDataLists.Count})..."); 255 | ImportModpack(ttmpDataList.Value, _textoolsModpack, ttmpDataList.Key); 256 | File.WriteAllText(modActiveConfFile, JsonConvert.SerializeObject(modActiveStates, Formatting.Indented)); 257 | PrintMessage($"Updated {modActiveConfFile} to reflect changes.", 1); 258 | _currentModpackNum++; 259 | } 260 | } 261 | 262 | List TTMP2DataList(List ttmpJson, ModPackJson ttmpData, bool useWizard, bool importAll) 263 | { 264 | List ttmpDataList = new List(); 265 | if (!useWizard && !importAll) 266 | useWizard = PromptWizardUsage(ttmpJson.Count); 267 | if (useWizard) 268 | { 269 | PrintMessage($"\nName: {ttmpData.Name}\nVersion: {ttmpData.Version}\nAuthor: {ttmpData.Author}\n"); 270 | ttmpJson = SimpleDataHandler(ttmpJson); 271 | } 272 | foreach (ModsJson mod in ttmpJson) 273 | { 274 | if (mod.ModPackEntry == null) 275 | mod.ModPackEntry = new ModPack { name = ttmpData.Name, author = ttmpData.Author, version = ttmpData.Version, url = ttmpData.Url }; 276 | ttmpDataList.Add(mod); 277 | } 278 | return ttmpDataList; 279 | } 280 | 281 | List TTMPDataList(DirectoryInfo ttmpPath, bool useWizard, bool importAll) 282 | { 283 | List ttmpJson = new List(); 284 | var originalModPackData = GetOldModpackJson(ttmpPath); 285 | string ttmpName = Path.GetFileNameWithoutExtension(ttmpPath.FullName); 286 | 287 | foreach (var modsJson in originalModPackData) 288 | { 289 | ttmpJson.Add(new ModsJson 290 | { 291 | Name = modsJson.Name, 292 | Category = modsJson.Category, 293 | FullPath = modsJson.FullPath, 294 | ModOffset = modsJson.ModOffset, 295 | ModSize = modsJson.ModSize, 296 | DatFile = modsJson.DatFile, 297 | IsDefault = false, 298 | ModPackEntry = new ModPack { name = ttmpName, author = "N/A", version = "1.0.0", url = "N/A" } 299 | }); 300 | } 301 | if (!useWizard && !importAll) 302 | useWizard = PromptWizardUsage(ttmpJson.Count); 303 | if (useWizard) 304 | { 305 | PrintMessage($"\nName: {ttmpName}\nVersion: N/A\nAuthor: N/A\n"); 306 | return SimpleDataHandler(ttmpJson); 307 | } 308 | return ttmpJson; 309 | } 310 | 311 | List GetOldModpackJson(DirectoryInfo ttmpPath) 312 | { 313 | List originalModPackData = new List(); 314 | var fs = new FileStream(ttmpPath.FullName, FileMode.Open, FileAccess.Read); 315 | ZipArchive archive = new ZipArchive(fs); 316 | ZipArchiveEntry mplFile = archive.GetEntry("TTMPL.mpl"); 317 | { 318 | using (var streamReader = new StreamReader(mplFile.Open())) 319 | { 320 | string line; 321 | while ((line = streamReader.ReadLine()) != null) 322 | { 323 | if (!line.ToLower().Contains("version")) 324 | originalModPackData.Add(JsonConvert.DeserializeObject(line)); 325 | } 326 | } 327 | } 328 | return originalModPackData; 329 | } 330 | 331 | bool PromptWizardUsage(int modCount) 332 | { 333 | bool userPicked = false; 334 | bool answer = false; 335 | 336 | if (modCount > 250) 337 | PrintMessage($"This modpack contains {modCount} mods, using the wizard could be a tedious process", 3); 338 | 339 | while (!userPicked && modCount > 1) 340 | { 341 | PrintMessage($"Would you like to use the Wizard for importing?\n(Y)es, let me select the mods\n(N)o, import everything"); 342 | string reply = Console.ReadKey().KeyChar.ToString().ToLower(); 343 | if (reply == "y") 344 | { 345 | answer = true; 346 | userPicked = true; 347 | } 348 | else if (reply == "n") 349 | { 350 | answer = false; 351 | userPicked = true; 352 | } 353 | PrintMessage("\n"); 354 | } 355 | return answer; 356 | } 357 | 358 | List WizardDataHandler(ModPackJson ttmpData) 359 | { 360 | Validators validation = new Validators(); 361 | List modpackData = new List(); 362 | PrintMessage($"\nName: {ttmpData.Name}\nVersion: {ttmpData.Version}\nAuthor: {ttmpData.Author}\n{ttmpData.Description}\n"); 363 | foreach (var page in ttmpData.ModPackPages) 364 | { 365 | if (ttmpData.ModPackPages.Count > 1) 366 | PrintMessage($"Page {page.PageIndex}"); 367 | foreach (var option in page.ModGroups) 368 | { 369 | bool userDone = false; 370 | while (!userDone) 371 | { 372 | PrintMessage($"{option.GroupName}\nChoices:"); 373 | List choices = new List(); 374 | foreach (var choice in option.OptionList) 375 | { 376 | string description = ""; 377 | if (!string.IsNullOrEmpty(choice.Description)) 378 | description = $"\n\t{choice.Description}"; 379 | choices.Add($" {option.OptionList.IndexOf(choice)} - {choice.Name}{description}"); 380 | } 381 | PrintMessage(string.Join("\n", choices)); 382 | int maxChoices = option.OptionList.Count; 383 | if (option.SelectionType == "Multi") 384 | { 385 | Console.Write("Choose none, one or multiple (eg: 1 2 3, 0-3, *): "); 386 | List wantedIndexes = WizardUserInputValidation(Console.ReadLine(), maxChoices, true); 387 | List pickedChoices = new List(); 388 | foreach (int index in wantedIndexes) 389 | pickedChoices.Add($"{index} - {option.OptionList[index].Name}"); 390 | if (!pickedChoices.Any()) 391 | pickedChoices.Add("nothing"); 392 | if (validation.PromptContinuation($"\nYou picked:\n{string.Join("\n", pickedChoices)}\nIs this correct?", true)) 393 | { 394 | foreach (int index in wantedIndexes) 395 | modpackData.AddRange(option.OptionList[index].ModsJsons); 396 | userDone = true; 397 | } 398 | } 399 | if (option.SelectionType == "Single") 400 | { 401 | Console.Write("Choose one (eg: 0 1 2 3): "); 402 | int wantedIndex = WizardUserInputValidation(Console.ReadLine(), maxChoices, false)[0]; 403 | if (validation.PromptContinuation($"\nYou picked:\n{wantedIndex} - {option.OptionList[wantedIndex].Name}\nIs this correct?", true)) 404 | { 405 | modpackData.AddRange(option.OptionList[wantedIndex].ModsJsons); 406 | userDone = true; 407 | } 408 | } 409 | Console.Write("\n"); 410 | } 411 | } 412 | } 413 | return modpackData; 414 | } 415 | 416 | List SimpleDataHandler(List ttmpJson) 417 | { 418 | Validators validation = new Validators(); 419 | List desiredMods = new List(); 420 | for (int i = 0; i < ttmpJson.Count; i = i + 50) 421 | { 422 | var items = ttmpJson.Skip(i).Take(50).ToList(); 423 | if (ttmpJson.Count > 50) 424 | PrintMessage($"{i}-{i + items.Count} ({ttmpJson.Count} total)"); 425 | bool userDone = false; 426 | while (!userDone) 427 | { 428 | PrintMessage("Mods:"); 429 | List mods = new List(); 430 | foreach (var item in items) 431 | mods.Add($" {items.IndexOf(item)} - {item.Name}, {GetMap(item.FullPath)}, {GetRace(item.FullPath)}"); 432 | PrintMessage(string.Join("\n", mods)); 433 | Console.Write("Choose mods you wish to import (eg: 1 2 3, 0-3, *): "); 434 | List wantedMods = WizardUserInputValidation(Console.ReadLine(), items.Count, true); 435 | List pickedMods = new List(); 436 | foreach (int index in wantedMods) 437 | pickedMods.Add(mods[index]); 438 | if (!pickedMods.Any()) 439 | pickedMods.Add("nothing"); 440 | if (validation.PromptContinuation($"\nYou picked:\n{string.Join("\n", pickedMods)}\nIs this correct?", true)) 441 | { 442 | foreach (int index in wantedMods) 443 | desiredMods.Add(items[index]); 444 | userDone = true; 445 | } 446 | Console.Write("\n"); 447 | } 448 | } 449 | return desiredMods; 450 | } 451 | 452 | List WizardUserInputValidation(string input, int totalChoices, bool canBeEmpty) 453 | { 454 | List desiredIndexes = new List(); 455 | if (!string.IsNullOrEmpty(input)) 456 | { 457 | string[] answers = input.Split(); 458 | foreach (string answer in answers) 459 | { 460 | if (answer == "*") 461 | { 462 | desiredIndexes = Enumerable.Range(0, totalChoices).ToList(); 463 | break; 464 | } 465 | if (answer.Contains("-")) 466 | { 467 | try 468 | { 469 | int[] targets = answer.Split('-').Select(int.Parse).ToArray(); 470 | desiredIndexes.AddRange(Enumerable.Range(targets[0], targets[1] - targets[0] + 1)); 471 | } 472 | catch 473 | { 474 | PrintMessage($"{answer} is not a valid range of choices", 2); 475 | } 476 | continue; 477 | } 478 | int wantedIndex; 479 | if (int.TryParse(answer, out wantedIndex)) 480 | { 481 | if (wantedIndex < totalChoices) 482 | { 483 | if (!desiredIndexes.Contains(wantedIndex)) 484 | desiredIndexes.Add(wantedIndex); 485 | } 486 | else 487 | PrintMessage($"There are only {totalChoices} choices, not {wantedIndex + 1}", 2); 488 | } 489 | else 490 | PrintMessage($"{answer} is not a valid choice", 2); 491 | } 492 | } 493 | else 494 | { 495 | if (!canBeEmpty) 496 | desiredIndexes.Add(0); 497 | } 498 | return desiredIndexes; 499 | } 500 | 501 | public List UpdateActiveModsConfFile(List ttmpJson) 502 | { 503 | List modActiveStates = new List(); 504 | if (File.Exists(modActiveConfFile) && !string.IsNullOrEmpty(File.ReadAllText(modActiveConfFile))) 505 | modActiveStates = JsonConvert.DeserializeObject>(File.ReadAllText(modActiveConfFile)); 506 | bool alreadyExists = false; 507 | int modIndex = 0; 508 | foreach (ModsJson entry in ttmpJson) 509 | { 510 | foreach (ModActiveStatus modState in modActiveStates) 511 | { 512 | if (entry.FullPath == modState.file) 513 | { 514 | modIndex = modActiveStates.IndexOf(modState); 515 | alreadyExists = true; 516 | break; 517 | } 518 | } 519 | if (!alreadyExists) 520 | modActiveStates.Add(new ModActiveStatus(entry)); 521 | else 522 | modActiveStates[modIndex] = new ModActiveStatus(entry); 523 | } 524 | return modActiveStates; 525 | } 526 | 527 | void ImportModpack(List ttmpJson, TTMP _textoolsModpack, DirectoryInfo ttmpPath) 528 | { 529 | var modlistPath = new DirectoryInfo(Path.Combine(_gameDirectory.FullName, "XivMods.json")); 530 | int totalModsImported = 0; 531 | 532 | try 533 | { 534 | string importErrors = ImportStarter(_textoolsModpack, ttmpPath, ttmpJson, modlistPath).Result; 535 | if (!string.IsNullOrEmpty(importErrors)) 536 | PrintMessage($"There were errors importing some mods:\n{importErrors}", 2); 537 | else 538 | { 539 | totalModsImported = ttmpJson.Count(); 540 | PrintMessage($"\n{totalModsImported} mod(s) successfully imported.", 1); 541 | } 542 | } 543 | catch (Exception ex) 544 | { 545 | PrintMessage($"There was an error attempting to import mods:\n{ex.Message}", 2); 546 | } 547 | } 548 | 549 | async Task ImportStarter(TTMP _textoolsModpack, DirectoryInfo ttmpPath, List ttmpJson, DirectoryInfo modlistPath) 550 | { 551 | var importer = ImportManager(_textoolsModpack, ttmpPath, ttmpJson, modlistPath); 552 | var watchdog = ImportWatcher(importer); 553 | await watchdog; 554 | await importer; 555 | return importer.Result; 556 | } 557 | 558 | async Task ImportWatcher(Task task) 559 | { 560 | int timeout = 10000; 561 | int loops = 0; 562 | bool importStartedOrFinished = false; 563 | PrintMessage("Waiting for import process to respond...\nIf percentage doesn't display for a few minutes, wipe your mod_cache.db and try again"); 564 | while (!importStartedOrFinished) 565 | { 566 | if (await Task.WhenAny(task, Task.Delay(timeout)) != task) 567 | { 568 | if (importStarted) 569 | importStartedOrFinished = true; 570 | else 571 | { 572 | task.Dispose(); 573 | task.Start(); 574 | } 575 | } 576 | else 577 | importStartedOrFinished = true; 578 | if (loops == 5 && !importStartedOrFinished) 579 | PrintMessage($"\nImport failed to start after {loops} retries", 2); 580 | loops++; 581 | } 582 | } 583 | 584 | async Task ImportManager(TTMP _textoolsModpack, DirectoryInfo ttmpPath, List ttmpJson, DirectoryInfo modlistPath) 585 | { 586 | var progressIndicator = new Progress<(int current, int total, string message)>(ReportProgress); 587 | var importResults = await _textoolsModpack.ImportModPackAsync(ttmpPath, ttmpJson, 588 | _indexDirectory, modlistPath, progressIndicator); 589 | return importResults.Errors; 590 | } 591 | 592 | void ReportProgress((int current, int total, string message) report) 593 | { 594 | importStarted = true; 595 | double progress = new double(); 596 | if (report.message == "Job Done.") 597 | report.message = "Done!"; 598 | if (report.total == 0) 599 | Console.Write("\r" + new string(' ', Console.WindowWidth) + $"\r{report.message}"); 600 | else if (report.message == "Creating TTMP File...") 601 | Console.Write("\r" + new string(' ', Console.WindowWidth) + $"\rFinalizing TTMP file..."); 602 | else 603 | { 604 | progress = ((double)report.current / (double)report.total) * 100; 605 | Console.Write("\r" + new string(' ', Console.WindowWidth) + $"\r{report.message} {(int)progress}%"); 606 | } 607 | } 608 | 609 | XivRace GetRace(string modPath) 610 | { 611 | var xivRace = XivRace.All_Races; 612 | 613 | if (modPath.Contains("ui/") || modPath.Contains(".avfx")) 614 | xivRace = XivRace.All_Races; 615 | else if (modPath.Contains("monster")) 616 | xivRace = XivRace.Monster; 617 | else if (modPath.Contains("bgcommon")) 618 | xivRace = XivRace.All_Races; 619 | else if (modPath.Contains(".tex") || modPath.Contains(".mdl") || modPath.Contains(".atex")) 620 | { 621 | if (modPath.Contains("accessory") || modPath.Contains("weapon") || modPath.Contains("/common/")) 622 | xivRace = XivRace.All_Races; 623 | else 624 | { 625 | if (modPath.Contains("demihuman")) 626 | xivRace = XivRace.DemiHuman; 627 | else if (modPath.Contains("/v")) 628 | { 629 | var raceCode = modPath.Substring(modPath.IndexOf("_c") + 2, 4); 630 | xivRace = XivRaces.GetXivRace(raceCode); 631 | } 632 | else 633 | { 634 | var raceCode = modPath.Substring(modPath.IndexOf("/c") + 2, 4); 635 | xivRace = XivRaces.GetXivRace(raceCode); 636 | } 637 | } 638 | } 639 | return xivRace; 640 | } 641 | 642 | string GetNumber(string modPath) 643 | { 644 | var number = "-"; 645 | 646 | if (modPath.Contains("/human/") && modPath.Contains("/body/")) 647 | { 648 | var subString = modPath.Substring(modPath.LastIndexOf("/b") + 2, 4); 649 | number = int.Parse(subString).ToString(); 650 | } 651 | 652 | if (modPath.Contains("/face/")) 653 | { 654 | var subString = modPath.Substring(modPath.LastIndexOf("/f") + 2, 4); 655 | number = int.Parse(subString).ToString(); 656 | } 657 | 658 | if (modPath.Contains("decal_face")) 659 | { 660 | var length = modPath.LastIndexOf(".") - (modPath.LastIndexOf("_") + 1); 661 | var subString = modPath.Substring(modPath.LastIndexOf("_") + 1, length); 662 | 663 | number = int.Parse(subString).ToString(); 664 | } 665 | 666 | if (modPath.Contains("decal_equip")) 667 | { 668 | var subString = modPath.Substring(modPath.LastIndexOf("_") + 1, 3); 669 | 670 | try 671 | { 672 | number = int.Parse(subString).ToString(); 673 | } 674 | catch 675 | { 676 | if (modPath.Contains("stigma")) 677 | number = "stigma"; 678 | else 679 | number = "Error"; 680 | } 681 | } 682 | 683 | if (modPath.Contains("/hair/")) 684 | { 685 | var t = modPath.Substring(modPath.LastIndexOf("/h") + 2, 4); 686 | number = int.Parse(t).ToString(); 687 | } 688 | 689 | if (modPath.Contains("/tail/")) 690 | { 691 | var t = modPath.Substring(modPath.LastIndexOf("l/t") + 3, 4); 692 | number = int.Parse(t).ToString(); 693 | } 694 | 695 | return number; 696 | } 697 | 698 | string GetType(string modPath) 699 | { 700 | var exRaw = Path.GetExtension(modPath); 701 | if(string.IsNullOrEmpty(exRaw)) 702 | return "Unknown"; 703 | var ext = exRaw.Substring(1); 704 | if(ext == "mdl") 705 | return "Model"; 706 | else if ( ext == "meta") 707 | return "Metadata"; 708 | else if (ext == "mtrl") 709 | return "Material"; 710 | else if(ext == "tex") 711 | return "Texture - " + GuessTextureUsage(modPath).ToString(); 712 | else 713 | return ext.ToUpper(); 714 | } 715 | 716 | string GetMap(string modPath) 717 | { 718 | var xivTexType = XivTexType.Other; 719 | 720 | if (modPath.Contains(".mdl")) 721 | return "3D"; 722 | 723 | if (modPath.Contains(".mtrl")) 724 | return "ColorSet"; 725 | 726 | if (modPath.Contains("ui/")) 727 | { 728 | var subString = modPath.Substring(modPath.IndexOf("/") + 1); 729 | return subString.Substring(0, subString.IndexOf("/")); 730 | } 731 | 732 | if (modPath.Contains("_s.tex") || modPath.Contains("skin_m")) 733 | xivTexType = XivTexType.Specular; 734 | else if (modPath.Contains("_d.tex")) 735 | xivTexType = XivTexType.Diffuse; 736 | else if (modPath.Contains("_n.tex")) 737 | xivTexType = XivTexType.Normal; 738 | else if (modPath.Contains("_m.tex")) 739 | xivTexType = XivTexType.Multi; 740 | else if (modPath.Contains(".atex")) 741 | { 742 | var atex = Path.GetFileNameWithoutExtension(modPath); 743 | return atex.Substring(0, 4); 744 | } 745 | else if (modPath.Contains("decal")) 746 | xivTexType = XivTexType.Mask; 747 | 748 | return xivTexType.ToString(); 749 | } 750 | 751 | public static XivTexType GuessTextureUsage(string path) { 752 | Regex _normRegex = new Regex("(_n(\\.|_))|(norm)"); 753 | Regex _diffuseRegex = new Regex("(_d(\\.|_))|(diff)"); 754 | Regex _specRegex = new Regex("(_s(\\.|_))|(spec)"); 755 | Regex _multiRegex = new Regex("(_m(\\.|_))|(mul)|(mask)"); 756 | Regex _reflectionRegex = new Regex("(catchlight|refl)"); 757 | Regex _iconRegex = new Regex("^ui/icon/"); 758 | Regex _mapRegex = new Regex("^ui/map/"); 759 | Regex _loadingImageRegex = new Regex("^ui/loadingimage/"); 760 | Regex _uldRegex = new Regex("^ui/uld/"); 761 | 762 | if(_normRegex.IsMatch(path)) 763 | return XivTexType.Normal; 764 | else if(_diffuseRegex.IsMatch(path)) 765 | return XivTexType.Diffuse; 766 | else if (_specRegex.IsMatch(path)) 767 | return XivTexType.Specular; 768 | else if (_multiRegex.IsMatch(path)) 769 | return XivTexType.Multi; 770 | else if (_reflectionRegex.IsMatch(path)) 771 | return XivTexType.Reflection; 772 | else if(_iconRegex.IsMatch(path)) 773 | return XivTexType.Icon; 774 | else if (_mapRegex.IsMatch(path)) 775 | return XivTexType.Map; 776 | else if (_loadingImageRegex.IsMatch(path)) 777 | return XivTexType.UI; 778 | else if (_uldRegex.IsMatch(path)) 779 | return XivTexType.UI; 780 | else 781 | return XivTexType.Other; 782 | } 783 | 784 | static readonly Dictionary FaceTypes = new Dictionary 785 | { 786 | {"fac", "Face"}, 787 | {"iri", "Iris"}, 788 | {"etc", "Etc"}, 789 | {"acc", "Accessory"} 790 | }; 791 | 792 | static readonly Dictionary HairTypes = new Dictionary 793 | { 794 | {"acc", "Accessory"}, 795 | {"hir", "Hair"}, 796 | }; 797 | 798 | static readonly Dictionary slotAbr = new Dictionary 799 | { 800 | {"met", "Head"}, 801 | {"glv", "Hands"}, 802 | {"dwn", "Legs"}, 803 | {"sho", "Feet"}, 804 | {"top", "Body"}, 805 | {"ear", "Ears"}, 806 | {"nek", "Neck"}, 807 | {"rir", "Ring Right"}, 808 | {"ril", "Ring Left"}, 809 | {"wrs", "Wrists"}, 810 | }; 811 | #endregion 812 | 813 | public void CreateModpack(DirectoryInfo outputFile) 814 | { 815 | string name = ""; 816 | if (outputFile.FullName == "/tmp/placeholder.ttmp") 817 | { 818 | PrintMessage("Name of the modpack?"); 819 | name = Console.ReadLine(); 820 | } 821 | else 822 | name = Path.GetFileNameWithoutExtension(outputFile.FullName); 823 | PrintMessage("Version of the modpack (in x.x.x format)?"); 824 | Version version = Version.Parse(Console.ReadLine()); 825 | PrintMessage("Author of the modpack?"); 826 | string author = Console.ReadLine(); 827 | DirectoryInfo modpackDir = new DirectoryInfo("/tmp/placeholder.ttmp"); 828 | if (outputFile.FullName == "/tmp/placeholder.ttmp") 829 | { 830 | PrintMessage("Full path to where you want to save the modpack"); 831 | modpackDir = new DirectoryInfo(Console.ReadLine()); 832 | } 833 | else 834 | modpackDir = new DirectoryInfo(Path.GetDirectoryName(outputFile.FullName)); 835 | if (!modpackDir.Exists) 836 | PrintMessage($"Can't find {modpackDir}. Does it exist?", 2); 837 | var ttmp = new TTMP(modpackDir, "FFXIV_Modding_Tool"); 838 | SimpleModPackData modpackData = new SimpleModPackData 839 | { 840 | Name = name, 841 | Author = author, 842 | Version = version, 843 | SimpleModDataList = new List() 844 | }; 845 | var dat = new Dat(new DirectoryInfo(_indexDirectory.FullName)); 846 | var localModData = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(_gameDirectory.FullName, "XivMods.json"))); 847 | foreach (Mod mod in localModData.Mods) 848 | { 849 | if (mod.source == "_INTERNAL_" || !mod.enabled) 850 | continue; 851 | var compressedSize = mod.data.modSize; 852 | try 853 | { 854 | var getCompressedFileSize = dat.GetCompressedFileSize(mod.data.modOffset, IOUtil.GetDataFileFromPath(mod.fullPath)); 855 | getCompressedFileSize.Wait(); 856 | compressedSize = getCompressedFileSize.Result; 857 | } catch 858 | { 859 | // If the calculation fails, the TexTools people just use the original size 860 | } 861 | SimpleModData modData = new SimpleModData 862 | { 863 | Name = mod.name, 864 | Category = mod.category, 865 | FullPath = mod.fullPath, 866 | ModOffset = mod.data.modOffset, 867 | ModSize = compressedSize, 868 | DatFile = mod.datFile 869 | }; 870 | modpackData.SimpleModDataList.Add(modData); 871 | } 872 | Progress<(int current, int total, string message)> progressIndicator = new Progress<(int current, int total, string message)>(ReportProgress); 873 | string modpackPath = ""; 874 | if (outputFile.FullName == "/tmp/placeholder.ttmp") 875 | modpackPath = Path.Combine(modpackDir.FullName, $"{name}.ttmp2"); 876 | else 877 | modpackPath = outputFile.FullName; 878 | bool overwriteModpack = false; 879 | Validators validation = new Validators(); 880 | if (File.Exists(modpackPath)) 881 | overwriteModpack = validation.PromptContinuation($"{modpackPath} already exists, do you want to overwrite it?"); 882 | PrintMessage("Creating modpack..."); 883 | try 884 | { 885 | var modpackCreation = ttmp.CreateSimpleModPack(modpackData, _indexDirectory, progressIndicator, overwriteModpack); 886 | modpackCreation.Wait(); 887 | PrintMessage($"\n{modpackPath} successfully created!", 1); 888 | } 889 | catch (Exception ex) 890 | { 891 | PrintMessage($"Something went wrong during modpack creation:\n{ex.Message}", 2); 892 | } 893 | } 894 | 895 | #region Index File Handling 896 | Dictionary IndexFiles() 897 | { 898 | Dictionary indexFiles = new Dictionary(); 899 | string indexExtension = ".win32.index"; 900 | string index2Extension = ".win32.index2"; 901 | List dataFiles = new List 902 | { 903 | XivDataFile._01_Bgcommon, 904 | XivDataFile._04_Chara, 905 | XivDataFile._06_Ui 906 | }; 907 | foreach (XivDataFile dataFile in dataFiles) 908 | { 909 | indexFiles.Add($"{dataFile.GetDataFileName()}{indexExtension}", dataFile); 910 | indexFiles.Add($"{dataFile.GetDataFileName()}{index2Extension}", dataFile); 911 | } 912 | return indexFiles; 913 | } 914 | 915 | public void BackupIndexes() 916 | { 917 | if (!_backupDirectory.Exists) 918 | { 919 | PrintMessage($"{_backupDirectory.FullName} does not exist, please specify an existing directory", 2); 920 | return; 921 | } 922 | if (IndexLocked()) 923 | { 924 | PrintMessage("Can't make backups while the game is running", 2); 925 | return; 926 | } 927 | string modFile = Path.Combine(_gameDirectory.FullName, "XivMods.json"); 928 | if (File.Exists(modFile)) 929 | { 930 | var modData = JsonConvert.DeserializeObject(File.ReadAllText(modFile)); 931 | if (modData.Mods.Count > 0) 932 | { 933 | bool allDisabled = true; 934 | foreach (Mod mod in modData.Mods) 935 | { 936 | if (mod.enabled) 937 | { 938 | allDisabled = false; 939 | break; 940 | } 941 | } 942 | if (!allDisabled) 943 | { 944 | PrintMessage("Can't make backups while the game is still modded.\nPlease disable all mods or reset your index files first", 2); 945 | return; 946 | } 947 | } 948 | } 949 | PrintMessage("Backing up index files..."); 950 | try 951 | { 952 | foreach (string indexFile in IndexFiles().Keys) 953 | { 954 | string indexPath = Path.Combine(_indexDirectory.FullName, indexFile); 955 | string backupPath = Path.Combine(_backupDirectory.FullName, indexFile); 956 | File.Copy(indexPath, backupPath, true); 957 | } 958 | } 959 | catch (Exception ex) 960 | { 961 | PrintMessage($"Something went wrong when backing up the index files\n{ex.Message}", 2); 962 | return; 963 | } 964 | PrintMessage("Successfully backed up the index files!", 1); 965 | } 966 | 967 | public void ResetMods() 968 | { 969 | bool allFilesAvailable = true; 970 | bool indexesUpToDate = true; 971 | var problemChecker = new ProblemChecker(_indexDirectory); 972 | if (!_backupDirectory.Exists) 973 | { 974 | PrintMessage($"{_backupDirectory.FullName} does not exist, please specify an existing directory", 2); 975 | return; 976 | } 977 | foreach (KeyValuePair indexFile in IndexFiles()) 978 | { 979 | string backupPath = Path.Combine(_backupDirectory.FullName, indexFile.Key); 980 | if (!File.Exists(backupPath)) 981 | { 982 | PrintMessage($"{indexFile.Key} not found, aborting...", 3); 983 | allFilesAvailable = false; 984 | break; 985 | } 986 | var outdatedBackupsCheck = problemChecker.CheckForOutdatedBackups(indexFile.Value, _backupDirectory); 987 | outdatedBackupsCheck.Wait(); 988 | if (!outdatedBackupsCheck.Result) 989 | { 990 | PrintMessage($"{indexFile.Key} is out of date, aborting...", 3); 991 | indexesUpToDate = false; 992 | break; 993 | } 994 | } 995 | if (!allFilesAvailable || !indexesUpToDate) 996 | { 997 | PrintMessage($"{_backupDirectory.FullName} has missing or outdated index files. You can either\n1. Download them from the TT discord\n2. Run this command again using \"backup\" instead of \"reset\" using a clean install of the game", 2); 998 | return; 999 | } 1000 | if (IndexLocked()) 1001 | { 1002 | PrintMessage("Can't reset the game while the game is running", 2); 1003 | return; 1004 | } 1005 | try 1006 | { 1007 | var reset = Task.Run(() => 1008 | { 1009 | var modding = new Modding(_indexDirectory); 1010 | var dat = new Dat(_indexDirectory); 1011 | var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.FullName, "XivMods.json")); 1012 | var backupFiles = Directory.GetFiles(_backupDirectory.FullName); 1013 | foreach (var backupFile in backupFiles) 1014 | { 1015 | if (backupFile.Contains(".win32.index")) 1016 | File.Copy(backupFile, $"{_indexDirectory}/{Path.GetFileName(backupFile)}", true); 1017 | } 1018 | 1019 | // Delete modded dat files 1020 | foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile))) 1021 | { 1022 | var datFiles = dat.GetModdedDatList(xivDataFile); 1023 | datFiles.Wait(); 1024 | 1025 | foreach (var datFile in datFiles.Result) 1026 | File.Delete(datFile); 1027 | 1028 | if (datFiles.Result.Count > 0) 1029 | problemChecker.RepairIndexDatCounts(xivDataFile); 1030 | } 1031 | 1032 | // Delete mod list 1033 | File.Delete(modListDirectory.FullName); 1034 | modding.CreateModlist(); 1035 | if (File.Exists(modActiveConfFile)) 1036 | File.WriteAllText(modActiveConfFile, string.Empty); 1037 | }); 1038 | reset.Wait(); 1039 | PrintMessage("Reset complete!", 1); 1040 | } 1041 | catch (Exception ex) 1042 | { 1043 | PrintMessage($"Something went wrong during the reset process\n{ex.Message}", 2); 1044 | } 1045 | } 1046 | #endregion 1047 | 1048 | #region Problem Checking 1049 | public void ProblemChecker() 1050 | { 1051 | var problemChecker = new ProblemChecker(_indexDirectory); 1052 | List problemsResolved = new List(); 1053 | List problemsUnresolved = new List(); 1054 | PrintMessage("Initializing problem check"); 1055 | PrintMessage("Checking index dat values..."); 1056 | List _indexDatRepairList = CheckIndexDatCounts(problemChecker); 1057 | if (_indexDatRepairList.Count > 0) 1058 | { 1059 | if (!IndexLocked()) 1060 | { 1061 | foreach (var xivDataFile in _indexDatRepairList) 1062 | problemChecker.RepairIndexDatCounts(xivDataFile); 1063 | PrintMessage("Rechecking index dat values..."); 1064 | List unfixedIndexes = CheckIndexDatCounts(problemChecker); 1065 | if (unfixedIndexes.Count > 0) 1066 | problemsUnresolved.Add("Issues with dat files were found, a reset is recommended"); 1067 | else 1068 | problemsResolved.Add("Index files needed repairs"); 1069 | } 1070 | else 1071 | problemsUnresolved.Add("Can't repair index files while the game is running"); 1072 | } 1073 | 1074 | PrintMessage("Checking index backups..."); 1075 | problemsUnresolved.AddRange(CheckBackups(problemChecker)); 1076 | 1077 | PrintMessage("Checking dat file..."); 1078 | problemsUnresolved.AddRange(CheckDat()); 1079 | 1080 | PrintMessage("Checking modlist..."); 1081 | problemsUnresolved.AddRange(CheckMods()); 1082 | 1083 | PrintMessage("Checking LoD settings..."); 1084 | Dictionary lodIssues = CheckLoD(); 1085 | problemsResolved.AddRange((from issue in lodIssues where issue.Value select issue.Key).ToList()); 1086 | problemsUnresolved.AddRange((from issue in lodIssues where !issue.Value select issue.Key).ToList()); 1087 | 1088 | if (problemsResolved.Count == 0 && problemsUnresolved.Count == 0) 1089 | PrintMessage("No problems found", 1); 1090 | if (problemsResolved.Count > 0) 1091 | PrintMessage($"\nThe following problems were found and resolved:\n{string.Join("\n", problemsResolved.ToArray())}", 1); 1092 | if (problemsUnresolved.Count > 0) 1093 | { 1094 | Console.Write("\n"); 1095 | PrintMessage($"The following problems could not be resolved:\n{string.Join("\n", problemsUnresolved.ToArray())}", 2); 1096 | } 1097 | } 1098 | 1099 | List CheckIndexDatCounts(ProblemChecker problemChecker) 1100 | { 1101 | var filesToCheck = new XivDataFile[] { XivDataFile._0A_Exd, XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui }; 1102 | List _indexDatIssueList = new List(); 1103 | foreach (var file in filesToCheck) 1104 | { 1105 | int atFile = Array.IndexOf(filesToCheck, file) + 1; 1106 | Console.Write($"\r{(int)(0.5f + ((100f * atFile) / filesToCheck.Length))}%"); 1107 | try 1108 | { 1109 | var datCountsCheck = problemChecker.CheckIndexDatCounts(file); 1110 | datCountsCheck.Wait(); 1111 | if (datCountsCheck.Result) 1112 | { 1113 | _indexDatIssueList.Add(file); 1114 | continue; 1115 | } 1116 | var largeDatCheck = problemChecker.CheckForLargeDats(file); 1117 | largeDatCheck.Wait(); 1118 | if (largeDatCheck.Result) 1119 | _indexDatIssueList.Add(file); 1120 | } 1121 | catch (Exception ex) 1122 | { 1123 | PrintMessage($"There was an issue checking index dat counts\n{ex.Message}", 3); 1124 | return new List(); 1125 | } 1126 | } 1127 | Console.Write("\n"); 1128 | return _indexDatIssueList; 1129 | } 1130 | 1131 | List CheckBackups(ProblemChecker problemChecker) 1132 | { 1133 | var filesToCheck = new XivDataFile[] { XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui }; 1134 | List problemsFound = new List(); 1135 | foreach (var file in filesToCheck) 1136 | { 1137 | int atFile = Array.IndexOf(filesToCheck, file) + 1; 1138 | Console.Write($"\r{(int)(0.5f + ((100f * atFile) / filesToCheck.Length))}%"); 1139 | string fileName = file.GetDataFileName(); 1140 | try 1141 | { 1142 | var backupFile = Path.Combine(_backupDirectory.FullName, $"{fileName}.win32.index"); 1143 | if (!File.Exists(backupFile)) 1144 | { 1145 | problemsFound.Add($"Index backups for {fileName} not found"); 1146 | continue; 1147 | } 1148 | var outdatedBackupsCheck = problemChecker.CheckForOutdatedBackups(file, _backupDirectory); 1149 | outdatedBackupsCheck.Wait(); 1150 | if (!outdatedBackupsCheck.Result) 1151 | problemsFound.Add($"Index backups for {fileName} are out of date"); 1152 | } 1153 | catch (Exception ex) 1154 | { 1155 | PrintMessage($"There was an issue checking the backed up index files\n{ex.Message}", 3); 1156 | return new List(); 1157 | } 1158 | } 1159 | Console.Write("\n"); 1160 | return problemsFound; 1161 | } 1162 | 1163 | List CheckDat() 1164 | { 1165 | List problemsFound = new List(); 1166 | string dataFileName = $"{XivDataFile._06_Ui.GetDataFileName()}.win32.dat1"; 1167 | var fileInfo = new FileInfo(Path.Combine(_indexDirectory.FullName, dataFileName)); 1168 | if (fileInfo.Exists) 1169 | { 1170 | if (fileInfo.Length < 10000000) 1171 | problemsFound.Add($"{dataFileName} is missing data"); 1172 | } 1173 | else 1174 | problemsFound.Add($"Game directory is missing {dataFileName}"); 1175 | PrintMessage("100%"); 1176 | return problemsFound; 1177 | } 1178 | 1179 | List CheckMods() 1180 | { 1181 | var modlistPath = new DirectoryInfo(Path.Combine(_gameDirectory.FullName, "XivMods.json")); 1182 | var modlistJson = JsonConvert.DeserializeObject(File.ReadAllText(modlistPath.FullName)); 1183 | var dat = new Dat(_indexDirectory); 1184 | List problemsFound = new List(); 1185 | if (modlistJson.Mods.Count > 0) 1186 | { 1187 | foreach (var mod in modlistJson.Mods) 1188 | { 1189 | int atMod = modlistJson.Mods.IndexOf(mod) + 1; 1190 | Console.Write($"\r{(int)(0.5f + ((100f * atMod) / modlistJson.Mods.Count))}%"); 1191 | if (mod.name.Equals(string.Empty)) 1192 | continue; 1193 | var fileName = Path.GetFileName(mod.fullPath); 1194 | if (mod.data.originalOffset == 0) 1195 | problemsFound.Add($"{fileName} has an original offset of 0. You will need to reset to remove this mod"); 1196 | else if (mod.data.modOffset == 0) 1197 | problemsFound.Add($"{fileName} has a mod offset of 0, disable it and reimport"); 1198 | 1199 | var fileType = 0; 1200 | try 1201 | { 1202 | fileType = dat.GetFileType(mod.data.modOffset, XivDataFiles.GetXivDataFile(mod.datFile)); 1203 | } 1204 | catch (Exception ex) 1205 | { 1206 | PrintMessage($"{ex.Message}", 2); 1207 | } 1208 | 1209 | if (fileType != 2 && fileType != 3 && fileType != 4) 1210 | problemsFound.Add($"{fileName} has an unknown file type ({fileType}), offset is most likely corrupt"); 1211 | } 1212 | Console.Write("\n"); 1213 | } 1214 | else 1215 | PrintMessage("No entries found in the modlist, skipping", 3); 1216 | return problemsFound; 1217 | } 1218 | 1219 | Dictionary CheckLoD() 1220 | { 1221 | Dictionary problemsFound = new Dictionary(); 1222 | if (_configDirectory == null) 1223 | { 1224 | PrintMessage("No config directory specified, skipping", 3); 1225 | return new Dictionary(); 1226 | } 1227 | Console.Write("\r0%"); 1228 | var problem = false; 1229 | var DX11 = false; 1230 | string ffxivCfg = Path.Combine(_configDirectory.FullName, "FFXIV.cfg"); 1231 | string ffxivbootCfg = Path.Combine(_configDirectory.FullName, "FFXIV_BOOT.cfg"); 1232 | 1233 | if (_configDirectory.Exists) 1234 | { 1235 | Console.Write("\r25%"); 1236 | if (File.Exists(ffxivbootCfg)) 1237 | { 1238 | var lines = File.ReadAllLines(ffxivbootCfg); 1239 | foreach (var line in lines) 1240 | { 1241 | if (line.Contains("DX11Enabled")) 1242 | { 1243 | var val = line.Substring(line.Length - 1, 1); 1244 | if (val.Equals("1")) 1245 | DX11 = true; 1246 | break; 1247 | } 1248 | } 1249 | } 1250 | else 1251 | problemsFound.Add($"Could not find {ffxivbootCfg}", false); 1252 | Console.Write("\r50%"); 1253 | if (File.Exists(ffxivCfg)) 1254 | { 1255 | var lines = File.ReadAllLines(ffxivCfg); 1256 | var lineNum = 0; 1257 | var tmpLine = 0; 1258 | foreach (var line in lines) 1259 | { 1260 | if (line.Contains("LodType")) 1261 | { 1262 | var val = line.Substring(line.Length - 1, 1); 1263 | if (DX11 && line.Contains("DX11")) 1264 | { 1265 | if (val.Equals("1")) 1266 | { 1267 | tmpLine = lineNum; 1268 | problem = true; 1269 | break; 1270 | } 1271 | } 1272 | else if (!DX11 && !line.Contains("DX11")) 1273 | { 1274 | if (val.Equals("1")) 1275 | { 1276 | tmpLine = lineNum; 1277 | problem = true; 1278 | break; 1279 | } 1280 | } 1281 | } 1282 | lineNum++; 1283 | } 1284 | Console.Write("\r75%"); 1285 | if (problem) 1286 | { 1287 | var line = lines[tmpLine]; 1288 | line = line.Substring(0, line.Length - 1) + 0; 1289 | lines[tmpLine] = line; 1290 | File.WriteAllLines(ffxivCfg, lines); 1291 | problemsFound.Add("LoD turned off, as some mods have issues with it turned on", true); 1292 | } 1293 | } 1294 | else 1295 | problemsFound.Add($"Could not find {ffxivCfg}", false); 1296 | } 1297 | else 1298 | problemsFound.Add($"{_configDirectory.FullName} does not exist", false); 1299 | Console.Write("\r100%\n"); 1300 | return problemsFound; 1301 | } 1302 | #endregion 1303 | 1304 | public void ReclaimSpace() 1305 | { 1306 | PrintMessage("Defragmenting..."); 1307 | try 1308 | { 1309 | long savedBytes = 0; 1310 | Progress<(int Count, int Total, string Message)> reporter = new Progress<(int Count, int Total, string Message)>(ReportProgress); 1311 | var modding = new Modding(_indexDirectory); 1312 | var defragmentation = modding.DefragmentModdedDats(reporter); 1313 | defragmentation.Wait(); 1314 | savedBytes = defragmentation.Result; 1315 | var savedSpace = FormatBytes(savedBytes); 1316 | PrintMessage($"\nDAT file defragmentation completed successfully. {savedSpace} of unused space has been recovered.", 1); 1317 | } 1318 | catch (Exception ex) 1319 | { 1320 | PrintMessage($"An error occurred during the defragmentation process: {ex.Message}", 2); 1321 | } 1322 | } 1323 | 1324 | static string FormatBytes(long bytes) 1325 | { 1326 | string[] Suffix = { "B", "KB", "MB", "GB", "TB" }; 1327 | int i; 1328 | double dblSByte = bytes; 1329 | for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024) 1330 | { 1331 | dblSByte = bytes / 1024.0; 1332 | } 1333 | 1334 | return String.Format("{0:0.##}{1}", dblSByte, Suffix[i]); 1335 | } 1336 | 1337 | public void ToggleModStates(bool enable) 1338 | { 1339 | string modstate = ""; 1340 | if (enable) 1341 | modstate = "on"; 1342 | else 1343 | modstate = "off"; 1344 | var modding = new Modding(_indexDirectory); 1345 | PrintMessage($"Turning {modstate} all mods..."); 1346 | try 1347 | { 1348 | var toggle = modding.ToggleAllMods(enable); 1349 | toggle.Wait(); 1350 | PrintMessage($"Successfully turned {modstate} all mods", 1); 1351 | } 1352 | catch (Exception e) 1353 | { 1354 | PrintMessage($"There was an issue turning {modstate} mods:\n{e}", 2); 1355 | } 1356 | } 1357 | 1358 | public void SetModActiveStates() 1359 | { 1360 | Modding modding = new Modding(_indexDirectory); 1361 | string modlistFile = Path.Combine(_gameDirectory.FullName, "XivMods.json"); 1362 | List modActiveStates = new List(); 1363 | if (!File.Exists(modActiveConfFile) || string.IsNullOrEmpty(File.ReadAllText(modActiveConfFile))) 1364 | { 1365 | PrintMessage("Can't enable/disable mods when no mods are installed", 2); 1366 | return; 1367 | } 1368 | if (File.Exists(modActiveConfFile) && !string.IsNullOrEmpty(File.ReadAllText(modActiveConfFile))) 1369 | modActiveStates = JsonConvert.DeserializeObject>(File.ReadAllText(modActiveConfFile)); 1370 | int enabled = 0; 1371 | int disabled = 0; 1372 | try 1373 | { 1374 | PrintMessage("Toggling mods..."); 1375 | foreach (ModActiveStatus modState in modActiveStates) 1376 | { 1377 | var toggle = modding.ToggleModStatus(modState.file, modState.enabled); 1378 | toggle.Wait(); 1379 | if (modState.enabled) 1380 | enabled++; 1381 | else 1382 | disabled++; 1383 | int atMod = modActiveStates.IndexOf(modState) + 1; 1384 | Console.Write($"\r{(int)(0.5f + ((100f * atMod) / modActiveStates.Count))}%... "); 1385 | } 1386 | } 1387 | catch (Exception ex) 1388 | { 1389 | PrintMessage($"Something went wrong during the toggle process\n{ex.Message}", 3); 1390 | return; 1391 | } 1392 | PrintMessage($"\nSuccessfully enabled {enabled} and disabled {disabled} out of {modActiveStates.Count} mods!", 1); 1393 | } 1394 | 1395 | private static DirectoryInfo GetConfigurationPath() 1396 | { 1397 | var _ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 1398 | //Workaround for Mac as dotnetcore doesn't seem to return a valid ApplicationData folder. 1399 | if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && string.IsNullOrEmpty(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))){ 1400 | _ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.config"; 1401 | } 1402 | return new DirectoryInfo(Path.Combine(_ConfigPath, "FFXIV_Modding_Tool")); 1403 | } 1404 | 1405 | static void Main(string[] args) 1406 | { 1407 | _projectconfDirectory = GetConfigurationPath(); 1408 | Config config = new Config(); 1409 | modActiveConfFile = Path.Combine(_projectconfDirectory.FullName, "modlist.cfg"); 1410 | //Can be removed on 1.0 release. Defined to move old files with typo 1411 | string _oldmodActiveConfFile = Path.Combine(_projectconfDirectory.FullName, "modlist.cgf"); 1412 | if (File.Exists(_oldmodActiveConfFile) && !File.Exists(modActiveConfFile)) 1413 | File.Move(_oldmodActiveConfFile, modActiveConfFile); 1414 | //End of temporary file rename section 1415 | Arguments arguments = new Arguments(); 1416 | arguments.ArgumentHandler(args); 1417 | } 1418 | } 1419 | } 1420 | --------------------------------------------------------------------------------