Updated webConverter for new files

This commit is contained in:
Spacehuhn
2020-07-15 21:47:15 +02:00
parent 04feef1298
commit e4cb8f8f31
3 changed files with 134 additions and 115 deletions

View File

@@ -89,8 +89,8 @@ for file in html_files:
hex_formatted_content += "0x" + char + ", "
hex_formatted_content = hex_formatted_content[:-2]
progmem_definitions += "const char " + array_name + "[] PROGMEM = {" + hex_formatted_content + "};\n"
copy_files_function += ' if(!LittleFS.exists(String(F("/web/' + base_file + '.gz"))) || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), String(F("/web/' + base_file + '.gz")));\n'
webserver_events += 'server.on(String(F("/' + base_file + '")).c_str(), HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_HTML);\n});\n'
copy_files_function += ' if(!LittleFS.exists("/web/' + base_file + '.gz") || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), "/web/' + base_file + '.gz");\n'
webserver_events += 'server.on("/' + base_file + '", HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_HTML);\n});\n'
for file in css_files:
base_file = os.path.basename(str(file))
@@ -117,8 +117,8 @@ for file in css_files:
hex_formatted_content += "0x" + char + ", "
hex_formatted_content = hex_formatted_content[:-2]
progmem_definitions += "const char " + array_name + "[] PROGMEM = {" + hex_formatted_content + "};\n"
copy_files_function += ' if(!LittleFS.exists(String(F("/web/' + base_file + '.gz"))) || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), String(F("/web/' + base_file + '.gz")));\n'
webserver_events += 'server.on(String(F("/' + base_file + '")).c_str(), HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_CSS);\n});\n'
copy_files_function += ' if(!LittleFS.exists("/web/' + base_file + '.gz") || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), "/web/' + base_file + '.gz");\n'
webserver_events += 'server.on("/' + base_file + '", HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_CSS);\n});\n'
for file in js_files:
q = PurePath('js')
@@ -149,8 +149,8 @@ for file in js_files:
hex_formatted_content += "0x" + char + ", "
hex_formatted_content = hex_formatted_content[:-2]
progmem_definitions += "const char " + array_name + "[] PROGMEM = {" + hex_formatted_content + "};\n"
copy_files_function += ' if(!LittleFS.exists(String(F("/web/js/' + base_file + '.gz"))) || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), String(F("/web/js/' + base_file + '.gz")));\n'
webserver_events += 'server.on(String(F("/js/' + base_file + '")).c_str(), HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JS);\n});\n'
copy_files_function += ' if(!LittleFS.exists("/web/js/' + base_file + '.gz") || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), "/web/js/' + base_file + '.gz");\n'
webserver_events += 'server.on("/js/' + base_file + '", HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JS);\n});\n'
for file in lang_files:
q = PurePath('lang')
@@ -179,12 +179,12 @@ for file in lang_files:
hex_formatted_content += "0x" + char + ", "
hex_formatted_content = hex_formatted_content[:-2]
progmem_definitions += "const char " + array_name + "[] PROGMEM = {" + hex_formatted_content + "};\n"
copy_files_function += ' if(!LittleFS.exists(String(F("/web/lang/' + base_file + '.gz"))) || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), String(F("/web/lang/' + base_file + '.gz")));\n'
webserver_events += 'server.on(String(F("/lang/' + base_file + '")).c_str(), HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n});\n'
copy_files_function += ' if(!LittleFS.exists("/web/lang/' + base_file + '.gz") || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), "/web/lang/' + base_file + '.gz");\n'
webserver_events += 'server.on("/lang/' + base_file + '", HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n});\n'
if(len(load_lang) > 0):
load_lang += ' else if(settings::getLang() == String(F("'+lang_name+'"))) sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n'
load_lang += ' else if(String(settings::getWebSettings().lang) == "'+lang_name+'") sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n'
else:
load_lang += ' if(settings::getLang() == String(F("'+lang_name+'"))) sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n'
load_lang += ' if(String(settings::getWebSettings().lang) == "'+lang_name+'") sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n'
base_file = os.path.basename(license_file_path)
new_file = str(os.path.join(str(compressed), str("LICENSE")))
@@ -206,7 +206,7 @@ for char in hex_content:
hex_formatted_content += "0x" + char + ", "
hex_formatted_content = hex_formatted_content[:-2]
progmem_definitions += "const char " + array_name + "[] PROGMEM = {" + hex_formatted_content + "};\n"
copy_files_function += ' if(!LittleFS.exists(String(F("/web/' + base_file + '.gz"))) || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), String(F("/web/' + base_file + '.gz")));\n'
copy_files_function += ' if(!LittleFS.exists("/web/' + base_file + '.gz") || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), "/web/' + base_file + '.gz");\n'
print("[+] Saving everything into webfiles.h...")
f = open(arduino_file_path, 'w')
@@ -232,19 +232,19 @@ f.write("#endif")
f.close()
print("\n[+] Done, happy uploading :)")
print("Here are the updated functions for wifi.h, in case you added or removed files:")
print("Here are the updated functions for wifi.cpp, in case you added or removed files:")
print();
print('if(!settings::getWebSpiffs()){')
print(' server.on(String(SLASH).c_str(), HTTP_GET, [](){')
print('if(!settings::getWebSettings().use_spiffs){')
print(' server.on("/", HTTP_GET, [](){')
print(' sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);')
print('});')
print(webserver_events)
print('}')
print("server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){")
print(" if(!settings::getWebSpiffs()){")
print('server.on("/lang/default.lang", HTTP_GET, [](){')
print(" if(!settings::getWebSettings().use_spiffs){")
print(load_lang)
print(' else handleFileRead(String(F("/web/lang/"))+settings::getLang()+String(F(".lang")));')
print(' else handleFileRead("/web/lang/"+String(settings::getWebSettings().lang)+".lang");')
print(' } else {')
print(' handleFileRead(String(F("/web/lang/"))+settings::getLang()+String(F(".lang")));')
print(' handleFileRead("/web/lang/"+String(settings::getWebSettings().lang)+".lang");')
print(' }')
print("});");
print("});")