@@ -55,12 +55,66 @@ ff::WADInfo ff::get_info_from_wad(const std::string& wad_path) {
5555 return ret;
5656}
5757
58- bool ff::replace_dol_in_wad (const std::string& wad, const std::string& dol) {
58+ void ff::set_ios_in_wad (const std::string& wad, int ios) {
59+ auto temp_dir = std::filesystem::temp_directory_path ();
60+ std::string input_file = (temp_dir / (" in-" + scrypto::generate_random_string (12 ))).string ();
61+ std::string output_file_base = (temp_dir / (" out-" + scrypto::generate_random_string (12 ))).string ();
62+ std::string output_file = output_file_base + " .wad" ;
63+
64+ try {
65+ std::filesystem::copy (wad, input_file);
66+ } catch (const std::exception& e) {
67+ throw std::runtime_error{" Failed to copy WAD file: " + std::string (e.what ())};
68+ }
69+
70+ std::string command = " Sharpii WAD -e \" " + input_file + " \" \" " + output_file_base + " \" -ios " + std::to_string (ios);
71+ #ifdef FF_DEBUG
72+ ff::logger.write_to_log (limhamn::logger::type::notice, " Command: " + command + " \n " );
73+ #endif
74+ if (std::system (command.c_str ()) != 0 ) {
75+ throw std::runtime_error{" Failed to set IOS in WAD file. Command failed." };
76+ }
77+
78+ try {
79+ std::filesystem::rename (output_file, wad);
80+ } catch (const std::exception& e) {
81+ throw std::runtime_error{" Rename failed: " + std::string (e.what ())};
82+ }
83+ }
84+
85+ void ff::set_title_id_in_wad (const std::string& wad, const std::string& title_id) {
86+ auto temp_dir = std::filesystem::temp_directory_path ();
87+ std::string input_file = (temp_dir / (" in-" + scrypto::generate_random_string (12 ))).string ();
88+ std::string output_file_base = (temp_dir / (" out-" + scrypto::generate_random_string (12 ))).string ();
89+ std::string output_file = output_file_base + " .wad" ;
90+
91+ try {
92+ std::filesystem::copy (wad, input_file);
93+ } catch (const std::exception& e) {
94+ throw std::runtime_error{" Failed to copy WAD file: " + std::string (e.what ())};
95+ }
96+
97+ std::string command = " Sharpii WAD -e \" " + input_file + " \" \" " + output_file_base + " \" -id " + title_id;
98+ #ifdef FF_DEBUG
99+ ff::logger.write_to_log (limhamn::logger::type::notice, " Command: " + command + " \n " );
100+ #endif
101+ if (std::system (command.c_str ()) != 0 ) {
102+ throw std::runtime_error{" Failed to set title ID in WAD file. Command failed." };
103+ }
104+
105+ try {
106+ std::filesystem::rename (output_file, wad);
107+ } catch (const std::exception& e) {
108+ throw std::runtime_error{" Rename failed: " + std::string (e.what ())};
109+ }
110+ }
111+
112+ void ff::replace_dol_in_wad (const std::string& wad, const std::string& dol) {
59113 if (!std::filesystem::exists (dol)) {
60114#ifdef FF_DEBUG
61115 ff::logger.write_to_log (limhamn::logger::type::notice, " DOL file does not exist: " + dol + " \n " );
62116#endif
63- return false ;
117+ throw std::runtime_error{ " DOL file does not exist: " + dol} ;
64118 }
65119
66120 auto temp_dir = std::filesystem::temp_directory_path ();
@@ -76,14 +130,14 @@ bool ff::replace_dol_in_wad(const std::string& wad, const std::string& dol) {
76130#ifdef FF_DEBUG
77131 ff::logger.write_to_log (limhamn::logger::type::error, " Failed to copy files: " + std::string (e.what ()) + " \n " );
78132#endif
79- return false ;
133+ throw std::runtime_error{ " Failed to copy files: " + std::string (e. what ())} ;
80134 }
81135
82136 if (!std::filesystem::exists (input_file) || !std::filesystem::exists (input_dol)) {
83137#ifdef FF_DEBUG
84138 ff::logger.write_to_log (limhamn::logger::type::error, " Input file or DOL file does not exist after copy.\n " );
85139#endif
86- return false ;
140+ throw std::runtime_error{ " Input file or DOL file does not exist after copy. " } ;
87141 }
88142
89143 std::string command = " Sharpii WAD -e \" " + input_file + " \" \" " + output_file_base + " \" -dol \" " + input_dol + " \" " ;
@@ -104,7 +158,7 @@ bool ff::replace_dol_in_wad(const std::string& wad, const std::string& dol) {
104158#endif
105159
106160 if (result_code != 0 || !std::filesystem::exists (output_file)) {
107- return false ;
161+ throw std::runtime_error{ " Failed to replace DOL in WAD file. Command failed or output file does not exist. " } ;
108162 }
109163
110164 try {
@@ -113,8 +167,6 @@ bool ff::replace_dol_in_wad(const std::string& wad, const std::string& dol) {
113167#ifdef FF_DEBUG
114168 ff::logger.write_to_log (limhamn::logger::type::error, " Rename failed: " + std::string (e.what ()) + " \n " );
115169#endif
116- return false ;
170+ throw std::runtime_error{ " Rename failed: " + std::string (e. what ())} ;
117171 }
118-
119- return std::filesystem::exists (wad);
120172}
0 commit comments