NULL

Question Switch - auto xci renaming tool

Discussion in 'Switch - Backup Loaders & Modchips' started by simbin, May 31, 2018.

  1. simbin
    OP

    simbin GBAtemp Fan

    Member
    3
    Jul 28, 2015
    United States
    wondering if it's possible to auto rename an entire folder of Switch xci files - based off their internal header info?

    such a tool would be extremely useful for people backing up large collections
     
  2. eskinner3742

    eskinner3742 GBAtemp Regular

    Member
    4
    Feb 21, 2016
    United States
    simbin likes this.
  3. simbin
    OP

    simbin GBAtemp Fan

    Member
    3
    Jul 28, 2015
    United States
    thanks I may end up using this, or just do it manually

    bummer having to rely on scene releases, which are named funky

    hopefully future tools will allow dumping our own carts, with better naming options
     
  4. wurstpistole

    wurstpistole I got 8 warning points

    Member
    12
    Nov 19, 2015
    Gambia, The
    They just name it after the official game IDs , nothing funky about it.
     
  5. thequickbrownfox

    thequickbrownfox Advanced Member

    Newcomer
    4
    May 7, 2018
    Poland
    You need nothing else but BRU.

    Using Bulk Rename Utility work on xci files in original folders, choose options "remove" to remove existing names and "append folder name", because with BBB releases folders are named clearly and correctly.
    You will end up with xci files named exactly like folders, so instead of "bbb-h-aeqka.xci" you'll have "Overcooked.Special.Edition.NSW-BigBlueBox.xci".

    Btw, BRU is an excellent tool, I can't imagine my life without it.
     
    Last edited by thequickbrownfox, Jun 1, 2018
    Sparkss, Greg956, Dr.doom and 2 others like this.
  6. snoofly

    snoofly GBAtemp Advanced Fan

    Member
    7
    Aug 18, 2015
    United States
    You're damn right about BRU - it's a godsend to collectors.
     
  7. WolfThatGoesMoo

    WolfThatGoesMoo Member

    Newcomer
    2
    Jun 1, 2018
    United States
    Hi, I've been a lurker for some time but I want to contribute to the scene if I can. I'm interested in making a program that does this, but I need a little help because I'm really a novice when it comes to this sort of thing.

    I have already made a program that renames xci files in bulk by using another tool previously posted here.

    Here's how my program does it:
    It creates an array list of the file names from a given directory, and loops it into the tool "XCI Explorer.exe" in order to extract the name found within the Game info's group.
    It then checks to see if the found name matches the file name. If it does...skip, else; it renames it appropriately. (Example: "bbb-h-adeba.xci" is renamed to "Just Dance 2018").
    This works well but is very clunky and the form of automation I use requires the user to stop interacting with the machine until the script has finished processing. (Essentially an ugly macro).

    Alternative method I attempted to use is to read the XML dump from nswdb and rename it that way, but I don't really care for this route. It relies on a third party to constantly update a database, or for me to build a scrapper for a
    site that may be taken down often and well scraping can be rude. It's too easy for it to be outdated, and ideally, I want the name sourced locally without internet being required.

    What I need help with:
    Obtaining the information XCI Explorer displays....or if I could get a modified version of it with command parameters to have it just spit out the extracted file name, that would be very helpful.

    I know..with that the work is basically done for me, but I'm not claiming nor attempting to make that part of the tool; especially when it's already made. Just trying to help out by making a re-naming tool.

    Any help would be appreciated!

    TLDR: Need help extracting header info to get game file name. I'm newb.
    XCI Reader uses nswdb dump to get name, BRU method uses folder name, and my method uses XCI Explorer and slow af clunky automation macro to get game name. These all have problems!
     
    Last edited by WolfThatGoesMoo, Jun 1, 2018
    simbin likes this.
  8. c80

    c80 Banned

    Banned
    2
    Jun 1, 2018
    Germany
    Why do you want to get the info from the file? There is a website with the information: nswdb . com You can download the data as an xml file: nswdb . com/xml.php Isn't this all you need?
     
  9. WolfThatGoesMoo

    WolfThatGoesMoo Member

    Newcomer
    2
    Jun 1, 2018
    United States
    There's 4 reasons why I want to grab the game title from the .xci file itself:

    1st being that I am already using that method to get the xml file from nswdb, and the problem is that checking the crc32 of each file (especially the larger sized files) takes forever, and in thus renaming an entire directory of games can take up to 15 minutes in my testing and I don't have very many games (I only grabbed backups I have physical copies of because I want digital versions.)

    2nd, the xml file can be outdated, taken down, relocated, etc making it require maintenance on my end which I'm not too interested in.

    3rd, when dumping my own cartridge, my crc32 values are different from the node <imgcrc> supplied, and in thus, unless you're only using bbb's releases, this renaming method wouldn't work for you. That's just not ideal.

    4th, I really don't feel this tool should force users to connect to the internet, especially when the information is locally source already, directly in the given directory.

    --

    Additional information:
    I threw the xci's into HdX and see where headers were stripped and where they are trimmed, but I really don't know how to navigate through it to find the title. Can anyone point me to a guide of interpreting it? I've tried searching for the title
    as a string converted to hex, and looking for the string as text and just haven't had any luck.
     
    Last edited by WolfThatGoesMoo, Jun 1, 2018
    simbin likes this.
  10. c80

    c80 Banned

    Banned
    2
    Jun 1, 2018
    Germany
    have a look at private void LoadGameInfos() in MainForm.cs of XCI Explorer. It reads the meta data from the XCI file:
    Code:
                    using (FileStream fileStream = File.OpenRead(this.TB_File.Text))
                    {
                        using (FileStream fileStream1 = File.OpenWrite("meta"))
                        {
                            BinaryReader binaryReader = new BinaryReader(fileStream);
                            BinaryWriter binaryWriter = new BinaryWriter(fileStream1);
                            fileStream.Position = this.metadataNcaOffset;
                            byte[] numArray = new byte[8192];
                            long num = this.metadataNcaSize;
                            while (true)
                            {
                                int num1 = fileStream.Read(numArray, 0, 8192);
                                int num2 = num1;
                                if (num1 <= 0 || num <= (long)0)
                                {
                                    break;
                                }
                                fileStream1.Write(numArray, 0, num2);
                                num -= (long)num2;
                            }
                            fileStream.Close();
                            binaryReader.Close();
                            binaryWriter.Close();
                        }
                    }
    
    after that hacktool is used with the meta:
    Code:
                    if (File.Exists("meta"))
                    {
                        Process process = new Process();
                        ProcessStartInfo processStartInfo = new ProcessStartInfo()
                        {
                            WindowStyle = ProcessWindowStyle.Hidden,
                            FileName = "hactool.exe",
                            Arguments = "-k keys.txt --romfsdir=data meta"
                        };
                        process.StartInfo = processStartInfo;
                        process.Start();
                        process.WaitForExit();
                        if (File.Exists("data\\control.nacp"))
                        {
                            byte[] numArray1 = File.ReadAllBytes("data\\control.nacp");
                            NACP.NACP_Datas[0] = new NACP.NACP_Data(numArray1.Skip<byte>(12288).Take<byte>(4096).ToArray<byte>());
                            for (int i = 0; i < (int)NACP.NACP_Strings.Length; i++)
                            {
                                NACP.NACP_Strings[i] = new NACP.NACP_String(numArray1.Skip<byte>(i * 768).Take<byte>(768).ToArray<byte>());
                                if (NACP.NACP_Strings[i].Check != 0)
                                {
                                    this.CB_RegionName.Items.Add(this.Language[i]);
                                    using (Bitmap bitmap = new Bitmap(string.Concat("data\\icon_", this.Language[i].Replace(" ", ""), ".dat")))
                                    {
                                        this.Icons[i] = new Bitmap(bitmap);
                                    }
                                    this.PB_GameIcon.BackgroundImage = this.Icons[i];
                                }
                            }
                            this.TB_GameRev.Text = NACP.NACP_Datas[0].GameVer;
                            this.TB_ProdCode.Text = NACP.NACP_Datas[0].GameProd;
                            if (this.TB_ProdCode.Text == "")
                            {
                                this.TB_ProdCode.Text = "No Prod. ID";
                            }
                            File.Delete("meta");
                            Directory.Delete("data", true);
                        }
                        this.CB_RegionName.SelectedIndex = 0;
                        return;
                    }
    
    The file control.nacp contains the Titel ID and more.

    Have a look at NACP.cs:

    Code:
            public class NACP_String
            {
                public byte[] Data;
                public byte Check;
                public string GameName;
                public string GameAuthor;
                public NACP_String(byte[] data)
                {
                    this.Data = data;
                    this.Check = this.Data[0];
                    this.GameName = Encoding.UTF8.GetString(this.Data.Take<byte>(512).ToArray<byte>());
                    this.GameAuthor = Encoding.UTF8.GetString(this.Data.Skip<byte>(512).Take<byte>(256).ToArray<byte>());
                }
            }
    
    As you can see, the GameName is at the very beginning of the file.

    Does this help?
     
  11. WolfThatGoesMoo

    WolfThatGoesMoo Member

    Newcomer
    2
    Jun 1, 2018
    United States
    This actually really does, thank you! I understand how that tool is obtaining it now, and I'll begin working on a solution. Big help c80, thank you so much
     
  12. WolfThatGoesMoo

    WolfThatGoesMoo Member

    Newcomer
    2
    Jun 1, 2018
    United States
    Okay, I finished making it. Will be creating a thread and trying to post it there. Not sure how rules or anything work for it though
     
    c80 and WiiuGold like this.
  13. WiiuGold

    WiiuGold GBAtemp Advanced Fan

    Member
    7
    Jan 5, 2015
    United States
    Cant wait to try it out
     
  14. WolfThatGoesMoo

    WolfThatGoesMoo Member

    Newcomer
    2
    Jun 1, 2018
    United States
    I'm attempting to make a thread but it keeps telling me that

    Do you have any ideas? There's no links in it. Just some screen shots and I've attached the file to the thread. Ohhh think the screen shots are considered links maybe

    --- Edit ----

    Okay, It was the screenshots and it's now fixed. It's up and ready for you to test if you'd like. Hope you enjoy!
     
    Last edited by WolfThatGoesMoo, Jun 5, 2018
  15. Nollog

    Nollog GBAtemp Addict

    Member
    7
    Oct 10, 2008
    Ireland
    It's not something that a user should be doing daily, surely it doesn't matter if it's a once off scan.

    You could do logic for skipping already processed files quite handedly.
     
  16. WolfThatGoesMoo

    WolfThatGoesMoo Member

    Newcomer
    2
    Jun 1, 2018
    United States
    Very true, I'm sure the usage on this is sort of one time thing and yep, logic to skip it is already added to the release.
    It's set up as an option called "Fast Mode", described on the post. It's an option so users can choose to quickly process the files, or to have it check the headers.
    Try it out if you'd like! and thanks for the advice
     
    Nollog likes this.
Loading...