From 3c76ba72c593781812f784911fb7c2a8f5a46eeb Mon Sep 17 00:00:00 2001
From: Steam Deck User <XargonWan@gmail.com>
Date: Sun, 3 Jul 2022 16:48:59 +0200
Subject: [PATCH] MANIFEST: flathub workaround fixed

---
 flathub-pr.sh               | 89 ++++++++++++++++++++-----------------
 net.retrodeck.retrodeck.yml | 59 ++++++++++++++++++++++++
 2 files changed, 108 insertions(+), 40 deletions(-)

diff --git a/flathub-pr.sh b/flathub-pr.sh
index 7699fad2..032dd05a 100755
--- a/flathub-pr.sh
+++ b/flathub-pr.sh
@@ -11,52 +11,61 @@ git submodule update
 # these must be included in the exclusion list as they must be redownloaded
 #sync -rav --progress --exclude={'res/screenshots/','shared-modules/','rd-submodules/retroarch','.git/','docs','retrodeck-flatpak/','retrodeck-flatpak-cooker/','.flatpak-builder/'} ~/RetroDECK/ ~/flathub/
 
-sync -rav --progress { \
-'overlays', \
-'rd-submodules', \
-'flathub.json', \
-'LICENSE', \
-'net.retrodeck.retrodeck.appdata.xml', \
-'net.retrodeck.retrodeck.desktop', \
-'net.retrodeck.retrodeck.yml', \
-'README.md', \
-} ~/flathub/
-
 cd ~/flathub
-git rm -r *
-# NOTE: be careful to remove the REAL (linked) submodules only
-rm -rf shared-modules
-rm -rf rd-submodules/retroarch
+git rm -rf *
+git clean -fxd # restroing git index
 
-# rebuilding submodules
-git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
-    while read path_key path
-    do
-        url_key=$(echo $path_key | sed 's/\.path/.url/');
-        branch_key=$(echo $path_key | sed 's/\.path/.branch/');
-        # If the url_key doesn't yet exist then backup up the existing
-        # directory if necessary and add the submodule
-        if [ ! $(git config --get "$url_key") ]; then
-            if [ -d "$path" ] && [ ! $(git config --get "$url_key") ]; then
-                mv "$path" "$path""_backup_""$(date +'%Y%m%d%H%M%S')";
-            fi;
-            url=$(git config -f .gitmodules --get "$url_key");
-            # If a branch is specified then use that one, otherwise
-            # default to master
-            branch=$(git config -f .gitmodules --get "$branch_key");
-            if [ ! "$branch" ]; then branch="master"; fi;
-            git submodule add -f -b "$branch" "$url" "$path";
-        fi;
-    done;
+cd ~/RetroDECK
+cp -rf \
+'rd-submodules' \
+'flathub.json' \
+'LICENSE' \
+'net.retrodeck.retrodeck.appdata.xml' \
+'net.retrodeck.retrodeck.desktop' \
+'net.retrodeck.retrodeck.yml' \
+'README.md' \
+~/flathub/
+cd ~/flathub
 
-# In case the submodule exists in .git/config but the url is out of date
+# #rebuilding submodules
+# git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
+#     while read path_key path
+#     do
+#         url_key=$(echo $path_key | sed 's/\.path/.url/');
+#         branch_key=$(echo $path_key | sed 's/\.path/.branch/');
+#         # If the url_key doesn't yet exist then backup up the existing
+#         # directory if necessary and add the submodule
+#         if [ ! $(git config --get "$url_key") ]; then
+#             if [ -d "$path" ] && [ ! $(git config --get "$url_key") ]; then
+#                 mv "$path" "$path""_backup_""$(date +'%Y%m%d%H%M%S')";
+#             fi;
+#             url=$(git config -f .gitmodules --get "$url_key");
+#             # If a branch is specified then use that one, otherwise
+#             # default to master
+#             branch=$(git config -f .gitmodules --get "$branch_key");
+#             if [ ! "$branch" ]; then branch="master"; fi;
+#             git submodule add -f -b "$branch" "$url" "$path";
+#         fi;
+#     done;
 
-git submodule sync;
+# # In case the submodule exists in .git/config but the url is out of date
+# git submodule sync
 
-# Now actually pull all the modules. I used to use this...
-git submodule foreach --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master)';
+# # Now actually pull all the modules. I used to use this...
+# git submodule foreach --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master)';
 
-git submodule update
+rm -rf .git/modules/*
+# Adding the real submodules, please update this every time a submodule is added
+git rm -rf shared-modules
+git submodule add https://github.com/flathub/shared-modules.git shared-modules
+
+git rm -rf rd-submodules/retroarch
+git submodule add https://github.com/flathub/org.libretro.RetroArch.git rd-submodules/retroarch
+
+# unbinds all submodules
+git submodule deinit -f .
+# checkout again
+git submodule update --init --recursive
 git add *
 git commit -m "Updating flathub"
 git push origin RetroDECK
\ No newline at end of file
diff --git a/net.retrodeck.retrodeck.yml b/net.retrodeck.retrodeck.yml
index b5f00a5e..0657a0bf 100644
--- a/net.retrodeck.retrodeck.yml
+++ b/net.retrodeck.retrodeck.yml
@@ -1008,10 +1008,69 @@ modules:
         url: https://github.com/hrydgard/ppsspp.git
         tag: v1.12.3
         commit: ce0a45cf0fcdd5bebf32208b9998f68dfc1107b7
+        disable-submodules: true # Part of the PPSSPP Flathub Workaround
         x-checker-data:
           type: git
           tag-pattern: "^v([\\d.]+)$"
 
+  # PPSSPP Flathub Workaround - START
+  # This workaround disables the PPSSPP libraries (disable-submodules: true) and install them separately
+  # This is only to make it buildable by the flathub builder as normaly it seems not to be needed
+  - type: git
+    dest: SDL/macOS
+    commit: f19a1d54b8a5af6cc378ea307e0ec676922eb4cc
+    url: https://github.com/hrydgard/ppsspp-mac-sdl
+  - type: git
+    dest: assets/debugger
+    commit: 36ad6b19b22de2075a01a4f0c765e3ef514dc38f
+    url: https://github.com/unknownbrackets/ppsspp-debugger.git
+  - type: git
+    dest: dx9sdk
+    commit: 7751cf73f5c06f1be21f5f31c3e2d9a7bacd3a93
+    url: https://github.com/hrydgard/minidx9.git
+  - type: git
+    dest: ext/SPIRV-Cross
+    commit: 9acb9ec31f5a8ef80ea6b994bb77be787b08d3d1
+    url: https://github.com/KhronosGroup/SPIRV-Cross.git
+  - type: git
+    dest: ext/armips
+    commit: 7885552b208493a6a0f21663770c446c3ba65576
+    url: https://github.com/Kingcom/armips.git
+  - type: git
+    dest: ext/discord-rpc
+    commit: 963aa9f3e5ce81a4682c6ca3d136cddda614db33
+    url: https://github.com/discordapp/discord-rpc.git
+  - type: git
+    dest: ext/glslang
+    commit: dc11adde23c455a24e13dd54de9b4ede8bdd7db8
+    url: https://github.com/hrydgard/glslang.git
+  - type: git
+    dest: ext/miniupnp
+    commit: 3a87be33e797ba947b2b2a5f8d087f6c3ff4d93e
+    url: https://github.com/hrydgard/miniupnp.git
+  - type: git
+    dest: ext/native/tools/prebuilt
+    commit: cbea79dc8fef4d9210e2bac7e7b9b5ff3388197a
+    url: https://github.com/hrydgard/ppsspp-freetype.git
+  - type: git
+    dest: ext/rapidjson
+    commit: 73063f5002612c6bf64fe24f851cd5cc0d83eef9
+    disable-submodules: true
+    url: https://github.com/Tencent/rapidjson.git
+  - type: git
+    dest: ext/zstd
+    commit: a488ba114ec17ea1054b9057c26a046fc122b3b6
+    url: https://github.com/facebook/zstd.git
+  - type: git
+    dest: ffmpeg
+    commit: 3ad7ddb9eb2af898dce8c4b5e9a28b77b3f7ddd7
+    url: https://github.com/hrydgard/ppsspp-ffmpeg.git
+  - type: git
+    dest: pspautotests
+    commit: 682a4303aba63a50c91ae0fa6928c9dac8ca9b92
+    url: https://github.com/hrydgard/pspautotests.git
+  # PPSSPP Flathub Workaround - END
+  
   # PPSSPP - END
 
   # External manifests end