diff --git a/Makefile b/Makefile index 7587d6b06..158ae9f57 100644 --- a/Makefile +++ b/Makefile @@ -178,7 +178,7 @@ cleanandcompile: .PHONY: start start: @echo "INFO Starting output/$(BUILD_TYPE)/simulator/$(HOST)/epsilon.$(EXE)" - @$(Q) output/$(BUILD_TYPE)/simulator/$(HOST)/epsilon.$(EXE) + @$(Q) output/$(BUILD_TYPE)/simulator/$(HOST)/epsilon.$(EXE) -v .PHONY: clean_run clean_run: cleanandcompile diff --git a/apps/code/app.cpp b/apps/code/app.cpp index 9de25b735..3b599e827 100644 --- a/apps/code/app.cpp +++ b/apps/code/app.cpp @@ -25,6 +25,7 @@ const Image * App::Descriptor::icon() { App::Snapshot::Snapshot() : #if EPSILON_GETOPT m_lockOnConsole(false), + m_hasBeenWiped(false), #endif m_scriptStore() { @@ -49,10 +50,12 @@ bool App::Snapshot::lockOnConsole() const { } void App::Snapshot::setOpt(const char * name, const char * value) { - if (strcmp(name, "wipe") == 0) { - m_scriptStore.deleteAllScripts(); - } if (strcmp(name, "script") == 0) { + if (!m_hasBeenWiped) { + m_hasBeenWiped = true; + m_scriptStore.deleteAllScripts(); + } + char * separator = const_cast(UTF8Helper::CodePointSearch(value, ':')); if (*separator == 0) { return; diff --git a/apps/code/app.h b/apps/code/app.h index 2deeb7f03..a42979e1e 100644 --- a/apps/code/app.h +++ b/apps/code/app.h @@ -34,6 +34,7 @@ public: private: #if EPSILON_GETOPT bool m_lockOnConsole; + bool m_hasBeenWiped; #endif ScriptStore m_scriptStore; }; diff --git a/apps/code/catalog.de.i18n b/apps/code/catalog.de.i18n index bbfd013aa..b0e507e92 100644 --- a/apps/code/catalog.de.i18n +++ b/apps/code/catalog.de.i18n @@ -69,6 +69,11 @@ PythonImportKandinsky = "kandinsky Modul importieren" PythonImportRandom = "random Modul importieren" PythonImportMath = "math Modul importieren" PythonImportMatplotlibPyplot = "Import matplotlib.pyplot module" +PythonImportOs = "os Modul importieren" +PythonOsUname = "Informieren Sie sich über das System" +PythonOsRemove = "Datei namens Dateiname entfernen" +PythonOsRename = "Datei mit altem Namen in neuen Namen umbenennen" +PythonOsListdir = "Dateien im Speicher auflisten" PythonImportTime = "time Modul importieren" PythonImportTurtle = "turtle Modul importieren" PythonIndex = "Index, bei dem x zuerst vorkommt" diff --git a/apps/code/catalog.en.i18n b/apps/code/catalog.en.i18n index 5f8657118..d546a6392 100644 --- a/apps/code/catalog.en.i18n +++ b/apps/code/catalog.en.i18n @@ -196,6 +196,11 @@ PythonTurtleSpeed = "Drawing speed between 0 and 10" PythonTurtleWrite = "Display a text" PythonUniform = "Floating point number in [a,b]" PythonImportTime = "Import time module" +PythonImportOs = "Import os module" +PythonOsUname = "Get infos about the system" +PythonOsRemove = "Remove file named filename" +PythonOsRename = "Rename file oldname to newname" +PythonOsListdir = "List files in memory" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Wait for n second" PythonMonotonic = "Return monotonic time" diff --git a/apps/code/catalog.es.i18n b/apps/code/catalog.es.i18n index 35fa14d4e..6a30ad360 100644 --- a/apps/code/catalog.es.i18n +++ b/apps/code/catalog.es.i18n @@ -196,6 +196,11 @@ PythonTurtleSpeed = "Drawing speed between 0 and 10" PythonTurtleWrite = "Display a text" PythonUniform = "Floating point number in [a,b]" PythonImportTime = "Import time module" +PythonImportOs = "Import os module" +PythonOsUname = " Información del sistema " +PythonOsRemove = "Eliminar un archivo" +PythonOsRename = "Renombrar archivo" +PythonOsListdir = "Archivos de la lista" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Esperar n segundos" PythonMonotonic = "Tiempo monótono de retorno" diff --git a/apps/code/catalog.fr.i18n b/apps/code/catalog.fr.i18n index 9b436400c..8561a0c05 100644 --- a/apps/code/catalog.fr.i18n +++ b/apps/code/catalog.fr.i18n @@ -196,6 +196,11 @@ PythonTurtleSpeed = "Vitesse du tracé entre 0 et 10" PythonTurtleWrite = "Affiche un texte" PythonUniform = "Nombre décimal dans [a,b]" PythonImportTime = "Importation du module temps" +PythonImportOs = "Importation du module os" +PythonOsUname = "Donne des infos sur le système" +PythonOsRemove = "Supprime le fichier nommé filename" +PythonOsRename = "Renomme oldname en newname" +PythonOsListdir = "Liste les fichiers" PythonTimePrefix = "Préfixe fonction du module temps" PythonTimeSleep = "Attendre n secondes" PythonMonotonic = "Retourne le temps monotonic" diff --git a/apps/code/catalog.hu.i18n b/apps/code/catalog.hu.i18n index c344ab2bf..74b3f66d8 100644 --- a/apps/code/catalog.hu.i18n +++ b/apps/code/catalog.hu.i18n @@ -70,6 +70,11 @@ PythonImportRandom = "Véletlenszerü modul importálása" PythonImportMath = "Import matematikai modul" PythonImportMatplotlibPyplot = "Import matplotlib.pyplot module" PythonImportTime = "Idömodul importálása" +PythonImportOs = "Os modul importálása" +PythonOsUname = "Információ a rendszerről" +PythonOsRemove = "Fájl eltávolítása" +PythonOsRename = "Fájl átnevezése" +PythonOsListdir = "Fájlok listázása" PythonImportTurtle = "Import teknös modul" PythonIndex = "Az elsö x esemény indexe" PythonInput = "Érték kérése" diff --git a/apps/code/catalog.it.i18n b/apps/code/catalog.it.i18n index eaecb080c..a1c54071a 100644 --- a/apps/code/catalog.it.i18n +++ b/apps/code/catalog.it.i18n @@ -71,6 +71,11 @@ PythonImportMath = "Importa modulo math" PythonImportMatplotlibPyplot = "Importa modulo matplotlib.pyplot" PythonImportTurtle = "Importa del modulo turtle" PythonImportTime = "Importa del modulo time" +PythonImportOs = "Importa modulo os" +PythonOsUname = "Ottieni informazioni sul sistema" +PythonOsRemove = "Rimuovere un file" +PythonOsRename = "Rinomina file" +PythonOsListdir = "Elenca file" PythonIndex = "Indice prima occorrenza di x" PythonInput = "Inserire un valore" PythonInsert = "Inserire x in posizione i-esima" diff --git a/apps/code/catalog.nl.i18n b/apps/code/catalog.nl.i18n index bbe2b04c5..bc0361ed8 100644 --- a/apps/code/catalog.nl.i18n +++ b/apps/code/catalog.nl.i18n @@ -70,6 +70,11 @@ PythonImportRandom = "Importeer random module" PythonImportMath = "Importeer math module" PythonImportMatplotlibPyplot = "Import matplotlib.pyplot module" PythonImportTime = "Importeer time module" +PythonImportOs = "Importeer os module" +PythonOsUname = " Krijg systeeminfo" +PythonOsRemove = "Een bestand verwijderen" +PythonOsRename = "Hernoem bestand" +PythonOsListdir = "Lijstbestanden" PythonImportTurtle = "Importeer turtle module" PythonIndex = "Index van de eerste x aanwezigheden" PythonInput = "Wijs een waarde toe" diff --git a/apps/code/catalog.pt.i18n b/apps/code/catalog.pt.i18n index f0b401b81..b0decb0ab 100644 --- a/apps/code/catalog.pt.i18n +++ b/apps/code/catalog.pt.i18n @@ -196,6 +196,11 @@ PythonTurtleSpeed = "Velocidade do desenho entre 0 e 10" PythonTurtleWrite = "Mostrar um texto" PythonUniform = "Número decimal em [a,b]" PythonImportTime = "Import time module" +PythonImportOs = "Import os module" +PythonOsUname = " Obter informações do sistema" +PythonOsRemove = "Remover um ficheiro" +PythonOsRename = "Renomear ficheiro" +PythonOsListdir = "Listar ficheiros" PythonTimePrefix = "time module function prefix" PythonTimeSleep = "Wait for n second" PythonMonotonic = "Return monotonic time" diff --git a/apps/code/catalog.universal.i18n b/apps/code/catalog.universal.i18n index 371a33f44..768a4d7d2 100644 --- a/apps/code/catalog.universal.i18n +++ b/apps/code/catalog.universal.i18n @@ -86,6 +86,8 @@ PythonCommandImportKandinsky = "import kandinsky" PythonCommandImportMath = "import math" PythonCommandImportMatplotlibPyplot = "import matplotlib.pyplot" PythonCommandImportRandom = "import random" +PythonCommandImportOs = "import os" +PythonCommandImportFromOs = "from os import *" PythonCommandImportTime = "import time" PythonCommandImportTurtle = "import turtle" PythonCommandIndex = "list.index(x)" @@ -212,6 +214,12 @@ PythonCommandTurtleFunctionWithoutArg = "turtle.\x11" PythonCommandUniform = "uniform(a,b)" PythonConstantE = "2.718281828459045" PythonConstantPi = "3.141592653589793" +PythonOsCommandUname = "uname()" +PythonOsCommandRemove = "remove(filename)" +PythonOsCommandRename = "rename(oldname, newname)" +PythonOsCommandRemoveWithoutArg = "remove(\x11)" +PythonOsCommandRenameWithoutArg = "rename(\x11,)" +PythonOsCommandListdir = "listdir()" PythonTurtleCommandBackward = "backward(x)" PythonTurtleCommandCircle = "circle(r)" PythonTurtleCommandColor = "color('c')" diff --git a/apps/code/python_toolbox.cpp b/apps/code/python_toolbox.cpp index bcd5ec925..fa8f72f24 100644 --- a/apps/code/python_toolbox.cpp +++ b/apps/code/python_toolbox.cpp @@ -256,6 +256,15 @@ const ToolboxMessageTree TimeModuleChildren[] = { ToolboxMessageTree::Leaf(I18n::Message::PythonCommandSleep, I18n::Message::PythonSleep) }; +const ToolboxMessageTree OsModuleChildren[] = { + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandImportOs, I18n::Message::PythonImportOs, false), + ToolboxMessageTree::Leaf(I18n::Message::PythonCommandImportFromOs, I18n::Message::PythonImportOs, false), + ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandUname, I18n::Message::PythonOsUname, false), + ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandRemove, I18n::Message::PythonOsRemove, false, I18n::Message::PythonOsCommandRemoveWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandRename, I18n::Message::PythonOsRename, false, I18n::Message::PythonOsCommandRenameWithoutArg), + ToolboxMessageTree::Leaf(I18n::Message::PythonOsCommandListdir, I18n::Message::PythonOsListdir, false) +}; + const ToolboxMessageTree modulesChildren[] = { ToolboxMessageTree::Node(I18n::Message::MathModule, MathModuleChildren), ToolboxMessageTree::Node(I18n::Message::CmathModule, CMathModuleChildren), @@ -264,6 +273,7 @@ const ToolboxMessageTree modulesChildren[] = { ToolboxMessageTree::Node(I18n::Message::RandomModule, RandomModuleChildren), ToolboxMessageTree::Node(I18n::Message::KandinskyModule, KandinskyModuleChildren), ToolboxMessageTree::Node(I18n::Message::IonModule, IonModuleChildren), + ToolboxMessageTree::Node(I18n::Message::OsModule, OsModuleChildren), ToolboxMessageTree::Node(I18n::Message::TimeModule, TimeModuleChildren) }; diff --git a/apps/code/toolbox.universal.i18n b/apps/code/toolbox.universal.i18n index 0600a4dfd..72bd47ef9 100644 --- a/apps/code/toolbox.universal.i18n +++ b/apps/code/toolbox.universal.i18n @@ -3,6 +3,7 @@ IonModule = "ion" KandinskyModule = "kandinsky" MathModule = "math" MatplotlibPyplotModule = "matplotlib.pyplot" +OsModule = "os" TimeModule = "time" TurtleModule = "turtle" ForLoopMenu = "For" diff --git a/ion/src/simulator/android/Makefile b/ion/src/simulator/android/Makefile index 271583307..8ec86055c 100644 --- a/ion/src/simulator/android/Makefile +++ b/ion/src/simulator/android/Makefile @@ -24,11 +24,11 @@ ifndef ARCH $(BUILD_DIR)/app/res/mipmap/ic_launcher.png: ion/src/simulator/assets/logo.svg | $$(@D)/. $(call rule_label,CONVERT) - $(Q) convert -background "#FFB734" $< $@ + $(Q) convert -background "#b1403b" $< $@ $(BUILD_DIR)/app/res/mipmap-v26/ic_launcher_foreground.png: ion/src/simulator/assets/logo.svg | $$(@D)/. $(call rule_label,CONVERT) - $(Q) convert -background none $< -resize 512x512 -gravity center -background none -extent 1024x1024 $@ + $(Q) convert -background none $< -resize 1024x1024 -gravity center -background none -extent 1024x1024 $@ $(BUILD_DIR)/app/res/%.xml: ion/src/simulator/android/src/res/%.xml | $$(@D)/. $(call rule_label,COPY) @@ -58,7 +58,7 @@ apk_deps += $(addprefix $(BUILD_DIR)/app/res/,mipmap/ic_launcher.png mipmap-v26/ $(BUILD_DIR)/%.apk: $(apk_deps) $(call rule_label,GRADLE) - $(Q) ANDROID_HOME=$(ANDROID_HOME) EPSILON_VERSION=$(EPSILON_VERSION) BUILD_DIR=$(BUILD_DIR) EPSILON_VARIANT=$* ion/src/simulator/android/gradlew -b ion/src/simulator/android/build.gradle assembleRelease + $(Q) ANDROID_HOME=$(ANDROID_HOME) EPSILON_VERSION=$(EPSILON_VERSION) OMEGA_VERSION=$(OMEGA_VERSION) BUILD_DIR=$(BUILD_DIR) EPSILON_VARIANT=$* ion/src/simulator/android/gradlew -b ion/src/simulator/android/build.gradle assembleRelease $(Q) cp $(BUILD_DIR)/app/outputs/apk/release/android-release*.apk $@ endif diff --git a/ion/src/simulator/android/build.gradle b/ion/src/simulator/android/build.gradle index 33184cff6..a620bb823 100644 --- a/ion/src/simulator/android/build.gradle +++ b/ion/src/simulator/android/build.gradle @@ -37,9 +37,9 @@ android { applicationId "io.github.omega.simulator" minSdkVersion 16 targetSdkVersion 28 - def (major, minor, patch) = System.getenv('EPSILON_VERSION').toLowerCase().tokenize('.').collect{it.toInteger()} + def (major, minor, patch) = System.getenv('OMEGA_VERSION').toLowerCase().tokenize('.').collect{it.toInteger()} versionCode major*1000000 + minor*10000 + patch * 100 - versionName System.getenv('EPSILON_VERSION') + versionName System.getenv('OMEGA_VERSION') } signingConfigs { environment { diff --git a/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java b/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java deleted file mode 100644 index ef056c93e..000000000 --- a/ion/src/simulator/android/src/java/com/numworks/calculator/EpsilonActivity.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.numworks.calculator; - -import java.util.Locale; - -import android.app.Activity; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.os.Bundle; -import android.util.Log; - -import com.google.android.gms.analytics.GoogleAnalytics; -import com.google.android.gms.analytics.Tracker; -import com.google.android.gms.analytics.HitBuilders; - -import org.libsdl.app.SDLActivity; - -public class EpsilonActivity extends SDLActivity { - private static GoogleAnalytics sAnalytics; - private static Tracker sTracker; - - protected String[] getLibraries() { - return new String[] { - "epsilon" - }; - } - - @Override - protected String[] getArguments() { - Locale currentLocale = getResources().getConfiguration().locale; - String[] arguments = {"--language", currentLocale.getLanguage()}; - return arguments; - } - - public Bitmap retrieveBitmapAsset(String identifier) { - Bitmap bitmap = null; - try { - bitmap = BitmapFactory.decodeStream( - this.getResources().getAssets().open(identifier) - ); - } catch (Exception e) { - Log.w("LoadTexture", "Coundn't load a file:" + identifier); - } - return bitmap; - } - - public void telemetryInit() { - sAnalytics = GoogleAnalytics.getInstance(this); - sTracker = sAnalytics.newTracker("UA-93775823-3"); - } - - public void telemetryScreen(String screenName) { - sTracker.setScreenName(screenName); - sTracker.send(new HitBuilders.ScreenViewBuilder().build()); - } - - public void telemetryEvent(String category, String action, String label) { - sTracker.send(new HitBuilders.EventBuilder() - .setCategory(category) - .setAction(action) - .setLabel(label) - .build() - ); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - /* This is done to hide the status bar and the bottom navigation buttons. - * - * In SDLActivity::onCreate, setWindowStyle(false) is called, which means - * the fullscreen mode is put to false. We call again the method here with - * true, in order not to modify the external sources. - * - * TODO: This was not needed for v12 of Epsilon, even though - * setWindowStyle(false) was already called in SDLActivity::onCreate. Find - * out why and make a proper fix? */ - super.onCreate(savedInstanceState); - if (!mBrokenLibraries) { - /* If mBrokenLibraries, SDL is not initialized by onCreate in - * SDLActivity.java. */ - setWindowStyle(true); - } - } - -} diff --git a/ion/src/simulator/android/src/java/io/github/omega/simulator/OmegaActivity.java b/ion/src/simulator/android/src/java/io/github/omega/simulator/OmegaActivity.java index c0b2b8962..e0613a692 100644 --- a/ion/src/simulator/android/src/java/io/github/omega/simulator/OmegaActivity.java +++ b/ion/src/simulator/android/src/java/io/github/omega/simulator/OmegaActivity.java @@ -40,9 +40,21 @@ public class OmegaActivity extends SDLActivity { return bitmap; } + @Override protected void onCreate(Bundle savedInstanceState) { + /* This is done to hide the status bar and the bottom navigation buttons. + * + * In SDLActivity::onCreate, setWindowStyle(false) is called, which means + * the fullscreen mode is put to false. We call again the method here with + * true, in order not to modify the external sources. + * + * TODO: This was not needed for v12 of Epsilon, even though + * setWindowStyle(false) was already called in SDLActivity::onCreate. Find + * out why and make a proper fix? */ super.onCreate(savedInstanceState); if (!mBrokenLibraries) { + /* If mBrokenLibraries, SDL is not initialized by onCreate in + * SDLActivity.java. */ setWindowStyle(true); } } diff --git a/ion/src/simulator/assets/logo.svg b/ion/src/simulator/assets/logo.svg index 7c4db4086..2790b3071 100644 --- a/ion/src/simulator/assets/logo.svg +++ b/ion/src/simulator/assets/logo.svg @@ -1,11 +1,19 @@ + id="svg4" + sodipodi:docname="logo.svg" + inkscape:version="1.0 (4035a4fb49, 2020-05-01)"> @@ -28,9 +36,25 @@ gridtolerance="10" guidetolerance="10" id="namedview6" - showgrid="false"/> + showgrid="false" + inkscape:document-rotation="0" + inkscape:zoom="0.10241699" + inkscape:cx="-688.3434" + inkscape:cy="1290.1447" + inkscape:window-width="1310" + inkscape:window-height="740" + inkscape:window-x="1970" + inkscape:window-y="312" + inkscape:window-maximized="1" + inkscape:current-layer="svg4" /> + + style="fill:#ffffff;stroke-width:2.41038" + sodipodi:nodetypes="scccsssscccssssssscssscssssss" /> diff --git a/ion/src/simulator/shared/main_sdl.cpp b/ion/src/simulator/shared/main_sdl.cpp index c5155c8bd..400cda9b0 100644 --- a/ion/src/simulator/shared/main_sdl.cpp +++ b/ion/src/simulator/shared/main_sdl.cpp @@ -10,12 +10,20 @@ #include #include #include +#include #include #include +#include static bool argument_screen_only = false; static bool argument_fullscreen = false; static bool argument_unresizable = false; +static bool argument_volatile = false; +static char* pref_path = nullptr; +static char* file_buffer = nullptr; + +static void loadPython(std::vector* arguments); +static void savePython(); void Ion::Timing::msleep(uint32_t ms) { SDL_Delay(ms); @@ -26,10 +34,21 @@ void print_help(char * program_name) { printf("Options:\n"); printf(" -f, --fullscreen Starts the emulator in fullscreen\n"); printf(" -s, --screen-only Disable the keyboard.\n"); + printf(" -v, --volatile Disable saving and loading python scripts from file.\n"); printf(" -u, --unresizable Disable resizing the window.\n"); printf(" -h, --help Show this help menu.\n"); } +int event_filter(void* userdata, SDL_Event* e) { + if (e->type == SDL_APP_TERMINATING || e->type == SDL_APP_WILLENTERBACKGROUND) { + savePython(); + } + + return 1; +} + + + int main(int argc, char * argv[]) { std::vector arguments(argv, argv + argc); @@ -43,6 +62,8 @@ int main(int argc, char * argv[]) { argument_fullscreen = true; } else if(strcmp(argv[i], "-u")==0 || strcmp(argv[i], "--unresizable")==0) { argument_unresizable = true; + } else if(strcmp(argv[i], "-v")==0 || strcmp(argv[i], "--volatile")==0) { + argument_volatile = true; } } @@ -57,13 +78,127 @@ int main(int argc, char * argv[]) { arguments.push_back(language); } +#ifndef __EMSCRIPTEN__ + if (!argument_volatile) { + loadPython(&arguments); + SDL_SetEventFilter(event_filter, NULL); + } +#endif + Ion::Simulator::Main::init(); + ion_main(arguments.size(), &arguments[0]); + +#ifndef __EMSCRIPTEN__ + if (!argument_volatile) { + savePython(); + } +#endif + Ion::Simulator::Main::quit(); + if (file_buffer != nullptr) + SDL_free(file_buffer); + if (pref_path != nullptr) + SDL_free(pref_path); + return 0; } +static void loadPython(std::vector* arguments) { + pref_path = SDL_GetPrefPath("io.github.omega", "omega-simulator"); + std::string path(pref_path); + printf("Loading from %s\n", (path + "python.dat").c_str()); + + SDL_RWops* save_file = SDL_RWFromFile((path + "python.dat").c_str(), "rb"); + + if (save_file != NULL) { + // Calculate checksum + uint64_t checksum = 0; + uint64_t calc_checksum = 0; + + SDL_RWread(save_file, &checksum, sizeof(uint64_t), 1); + + uint8_t curr_check = 0; + + while(SDL_RWread(save_file, &curr_check, sizeof(uint8_t), 1)) { + calc_checksum += curr_check; + } + + if (checksum == calc_checksum) { + arguments->push_back("--code-wipe"); + arguments->push_back("true"); + + uint64_t length = SDL_RWseek(save_file, 0, RW_SEEK_END) - sizeof(uint64_t); + + SDL_RWseek(save_file, sizeof(uint64_t), RW_SEEK_SET); + + file_buffer = (char*) SDL_malloc(length); + SDL_RWread(save_file, file_buffer, length, 1); + + // printf("Length: %ld\n", length); + size_t i = 0; + while(i < length) { + uint16_t size = *(uint16_t*)(file_buffer + i); + arguments->push_back("--code-script"); + arguments->push_back((char*)(file_buffer + i + sizeof(uint16_t))); + // printf("Loaded size=%d i=%ld, %s\n", size, i+size, (char*)(file_buffer + i + sizeof(uint16_t))); + i += size + sizeof(uint16_t); + } + } + } +} + +static void savePython() { + std::string path(pref_path); + + printf("Saving to %s\n", (path + "python.dat").c_str()); + + SDL_RWops* save_file = SDL_RWFromFile((path + "python.dat").c_str(), "wb+"); + + if (save_file != NULL) { + + // Placeholder for checksum + uint64_t checksum = 0; + SDL_RWwrite(save_file, &checksum, sizeof(uint64_t), 1); + + uint16_t num = (uint16_t) Ion::Storage::sharedStorage()->numberOfRecordsWithExtension("py"); + + // Write all checksums + for(uint16_t i = 0; i < num; i++) { + Ion::Storage::Record record = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex("py", i); + + const char* record_name = record.fullName(); + uint16_t record_name_len = strlen(record_name); + + Ion::Storage::Record::Data record_data = record.value(); + + uint16_t total_length = record_name_len + record_data.size; + + SDL_RWwrite(save_file, &total_length, sizeof(uint16_t), 1); + + SDL_RWwrite(save_file, record_name, record_name_len, 1); + SDL_RWwrite(save_file, ":", 1, 1); + // Remove import status, keep trailing \x00 + SDL_RWwrite(save_file, ((char*)record_data.buffer + 1), record_data.size - 1, 1); + } + + // Compute and write checksum + + SDL_RWseek(save_file, sizeof(uint64_t), RW_SEEK_SET); + uint8_t curr_check = 0; + + while(SDL_RWread(save_file, &curr_check, sizeof(uint8_t), 1)) { + checksum += curr_check; + } + + SDL_RWseek(save_file, 0, RW_SEEK_SET); + SDL_RWwrite(save_file, &checksum, sizeof(uint64_t), 1); + + SDL_RWclose(save_file); + } +} + namespace Ion { namespace Simulator { namespace Main { diff --git a/python/port/mod/os/uname_result.cpp b/python/port/mod/os/uname_result.cpp deleted file mode 100644 index 616f5dacc..000000000 --- a/python/port/mod/os/uname_result.cpp +++ /dev/null @@ -1,18 +0,0 @@ -extern "C" { -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "uname_result.h" -} - -STATIC void uname_result_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind); -STATIC mp_obj_t uname_result_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -STATIC void uname_result_attr(mp_obj_t self_in, qstr attribute, mp_obj_t *destination); - - diff --git a/python/port/mod/os/uname_result.h b/python/port/mod/os/uname_result.h deleted file mode 100644 index e69de29bb..000000000