Mihail5412 / Unity-Android-Files-Opener

Allows your unity android application to open files on local drive
MIT License
18 stars 4 forks source link

Package renaming error #8

Open SteriCraft opened 1 month ago

SteriCraft commented 1 month ago

Hi,

First of all thank you for your amazing work, your plugin allowed me to open an *.apk download from within my app and implement an auto-update functionality!

I'm encountering a recurrent issue (not critical but impractical and a bit painful each time) with a "Package renamer" method. I have no idea what is the purpose of this piece of code.

After ~100 script recompile (while working on my project), I get thousands of "index out of array bounds" errors. It comes from this:

private static void ChangePackageName()
{
    string manifestPath = Path.Combine(pathToTempFolder, MANIFEST_NAME);
    string manifestText = File.ReadAllText(manifestPath);

    int manifestPackageNameStartIndex = manifestText.IndexOf("package=\"") + 9;
    int manifestPackageNameEndIndex = manifestText.IndexOf("\">", manifestPackageNameStartIndex);
    // ------ CRASHES HERE ------
    string manifestPackageName = manifestText.Substring(manifestPackageNameStartIndex, manifestPackageNameEndIndex - manifestPackageNameStartIndex);
    // --------------------------

    manifestText = manifestText.Replace("package=\"" + manifestPackageName, "package=\"" + PlayerSettings.applicationIdentifier);
    manifestText = manifestText.Replace("android:authorities=\"" + manifestPackageName, "android:authorities=\"" + PlayerSettings.applicationIdentifier);
    File.WriteAllText(manifestPath, manifestText);

    string filepathsPath = Path.Combine(pathToTempFolder, PROVIDER_PATHS_NAME);
    string filepathsText = File.ReadAllText(filepathsPath);

    int filepathsPackageNameStartIndex = filepathsText.IndexOf("data/") + 5;
    int filepathsPackageNameEndIndex = filepathsText.IndexOf("\" name", filepathsPackageNameStartIndex);
    string filepathsPackageName = filepathsText.Substring(filepathsPackageNameStartIndex, filepathsPackageNameEndIndex - filepathsPackageNameStartIndex);

    filepathsText = filepathsText.Replace("data/" + filepathsPackageName, "data/" + PlayerSettings.applicationIdentifier);
    File.WriteAllText(filepathsPath, filepathsText);

    lastPackageName = PlayerSettings.applicationIdentifier;
}

In file Assets/Editor/PackageNameChanger.cs

This snippet is executed in editor mode and prevent building my application. My current fix is to remove the plugin altogether and reinstall it file by file

Maybe I'm doing something wrong, any clue? Thanks in advance.

SteriCraft commented 1 month ago

[UPDATE]: Now, without touching anything, just restarting the project next day to work on it, it doesn't work anymore at all. When I remove the plugin, the problem disappears.

Here is the error message: image

I'm really clueless...

Mihail5412 commented 1 month ago

Hi @SteriCraft, what version of Unity do you use?

SteriCraft commented 1 month ago

Hi @Mihail5412, sorry I forgot basic informations: