public static List <ContentRule> GetCommonRules(short contentGroup, long titleID) { List <ContentRule> commonRules = new List <ContentRule>(); ContentDetails commonDetailsCode = new ContentDetails(false, Settings.groupid_code, 0x0L, Settings.fstflags_code); ContentDetails commonDetailsMeta = new ContentDetails(true, Settings.groupid_meta, 0x0L, Settings.fstflags_meta); ContentDetails commonDetailsPreload = new ContentDetails(true, Settings.groupid_code, 0x0L, Settings.fstflags_code); ContentDetails commonDetailsContent = new ContentDetails(true, contentGroup, titleID, Settings.fstflags_content); commonRules.Add(new ContentRule(@"^/code/app\.xml$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/code/cos\.xml$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/meta/meta\.xml$", commonDetailsMeta)); commonRules.Add(new ContentRule(@"^/meta/((?!\.xml).)*$", commonDetailsMeta)); commonRules.Add(new ContentRule(@"^/meta/bootMovie\.h264$", commonDetailsMeta)); commonRules.Add(new ContentRule(@"^/meta/bootLogoTex\.tga$", commonDetailsMeta)); commonRules.Add(new ContentRule(@"^/meta/Manual\.bfma$", commonDetailsMeta)); commonRules.Add(new ContentRule(@"^/meta/.*\.jpg$", commonDetailsMeta)); commonRules.Add(new ContentRule(@"/code/.*(\.rpx|\.rpl)$", commonDetailsCode, true)); commonRules.Add(new ContentRule(@"^/code/preload\.txt$", commonDetailsPreload)); commonRules.Add(new ContentRule(@"^/code/fw\.img$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/code/fw\.tmd$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/code/htk\.bin$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/code/rvlt\.tik$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/code/rvlt\.tmd$", commonDetailsCode)); commonRules.Add(new ContentRule(@"^/content/.*$", commonDetailsContent)); return(commonRules); }
private static bool SetContentRecursiveRule(string path, FSTEntry currentEntry, Contents targetContents, ContentDetails details, Regex regex) { path += currentEntry.filename + "/"; bool matchFound = false; if (currentEntry.children.Count == 0) { if (regex.IsMatch(path)) { Console.WriteLine($"Set content to {cur_content.ID:X} ({cur_content_size:X},{currentEntry.fileSize:X}) for: {path}"); currentEntry.SetContent(cur_content); return(true); } return(false); } foreach (FSTEntry child in currentEntry.children) { if (child.isDir) { matchFound |= SetContentRecursiveRule(path, child, targetContents, details, regex); } else { string childPath = path + child.filename; if (regex.IsMatch(childPath)) { if (cur_content_size + child.fileSize > MAX_CONTENT_LENGTH) { Console.WriteLine($"Info: Target content size is bigger than {MAX_CONTENT_LENGTH} bytes. Content will be split into multiple files."); cur_content = targetContents.GetNewContent(details); cur_content_size = 0; } cur_content_size += child.fileSize; Console.WriteLine($"Set content to {cur_content.ID:X} ({cur_content_size:X},{child.fileSize:X}) for: {childPath}"); child.SetContent(cur_content); matchFound = true; } } } if (matchFound) { currentEntry.SetContent(cur_content_first); } return(matchFound); }
private ContentRule(string pattern, ContentDetails details, bool contentPerMatch = false) { this.pattern = pattern; this.details = details; this.contentPerMatch = contentPerMatch; }
private static Content SetNewContentRecursiveRule(string path, FSTEntry currentEntry, Contents targetContents, ContentDetails details, Regex regex) { path += currentEntry.filename + "/"; Content result = null; if (currentEntry.children.Count == 0) { if (regex.IsMatch(path)) { result = targetContents.GetNewContent(details); } } foreach (FSTEntry child in currentEntry.children) { if (child.isDir) { result = SetNewContentRecursiveRule(path, child, targetContents, details, regex) ?? result; } else { string childPath = path + child.filename; if (regex.IsMatch(childPath)) { Content result_content = targetContents.GetNewContent(details); Console.WriteLine($"Set content to {result_content.ID:X} for: {childPath}"); child.SetContent(result_content); result = result_content; } } } if (result != null) { currentEntry.SetContent(result); } return(result); }