Exemplo n.º 1
0
        private static bool ExtractFilesFromArchive(UnityVersion version)
        {
            string internal_path = null;
            string archive_path  = cache_path;

            switch (OperationMode)
            {
            // Unity Dependencies for Unstripping Only
            case OperationModes.Normal:
            default:
                if (version.Version[0] == 3)
                {
                    internal_path = "Data/PlaybackEngines/windows64standaloneplayer/";
                }
                else if (version.Version[0] == 4)
                {
                    if (version.Version[1] >= 5)
                    {
                        internal_path = "Data/PlaybackEngines/windowsstandalonesupport/Variations/win64_nondevelopment/Data/";
                    }
                    else
                    {
                        internal_path = "Data/PlaybackEngines/windows64standaloneplayer/";
                    }
                }
                else if ((version.Version[0] == 5) && (version.Version[1] <= 2))
                {
                    internal_path = "./Unity/Unity.app/Contents/PlaybackEngines/WindowsStandaloneSupport/Variations/win64_nondevelopment_mono/Data/";
                }
                else if (version.Version[0] > 2021 || (version.Version[0] == 2021 && version.Version[1] >= 2))
                {
                    internal_path = "./Variations/win64_player_nondevelopment_mono/Data/";
                }
                else
                {
                    internal_path = "./Variations/win64_nondevelopment_mono/Data/";
                }

                if (version.UsePayloadExtraction)
                {
                    Logger.Msg($"Extracting Payload...");
                    if (!ArchiveHandler.ExtractFiles(AppDomain.CurrentDomain.BaseDirectory, archive_path, "Payload~"))
                    {
                        return(false);
                    }
                    archive_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Payload~");
                }

                Logger.Msg("Extracting DLLs from Archive...");
                return(ArchiveHandler.ExtractFiles(temp_folder_path, archive_path, internal_path + "Managed/*.dll"));


            // Full Android Libraries
            case OperationModes.Android_Il2Cpp:
            case OperationModes.Android_Mono:
                string rootpath    = "$INSTDIR$*";
                string basefolder  = $"{rootpath}/Variations/{((OperationMode == OperationModes.Android_Il2Cpp) ? "il2cpp" : "mono")}/";
                string libfilename = "libunity.so";

                Logger.Msg($"Extracting {libfilename} from Archive...");
                if (!ArchiveHandler.ExtractFiles(temp_folder_path, archive_path, $"{basefolder}Release/Libs/*/{libfilename}", true))
                {
                    return(false);
                }

                Logger.Msg("Fixing Folder Structure...");
                string libsfolderpath = Path.Combine(temp_folder_path, "Libs");
                if (!Directory.Exists(libsfolderpath))
                {
                    Directory.CreateDirectory(libsfolderpath);
                }
                foreach (string filepath in Directory.GetFiles(temp_folder_path, libfilename, SearchOption.AllDirectories))
                {
                    Logger.Msg($"Moving {filepath}");
                    DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(filepath));

                    string newpath = Path.Combine(libsfolderpath, dir.Name);
                    if (!Directory.Exists(newpath))
                    {
                        Directory.CreateDirectory(newpath);
                    }
                    File.Move(filepath, Path.Combine(newpath, Path.GetFileName(filepath)));
                }

                string rootfolder = Directory.GetDirectories(temp_folder_path, rootpath).First();
                Logger.Msg($"Removing {rootfolder}");
                Directory.Delete(rootfolder, true);

                Logger.Msg($"Extracting Managed Folder...");
                string newmanagedfolder = Path.Combine(temp_folder_path, "Managed");
                if (!Directory.Exists(newmanagedfolder))
                {
                    Directory.CreateDirectory(newmanagedfolder);
                }

                return(ArchiveHandler.ExtractFiles(newmanagedfolder, archive_path, basefolder + "Managed/*.dll"));
            }
        }
Exemplo n.º 2
0
        private static bool ProcessUnityVersion(UnityVersion version)
        {
            if (!VersionFilter(version))
            {
                return(false);
            }

            string zip_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{version.VersionStr}.zip");

            if (File.Exists(zip_path))
            {
                File.Delete(zip_path);
            }

            string downloadurl = version.DownloadURL;

            if ((OperationMode == OperationModes.Android_Il2Cpp) ||
                (OperationMode == OperationModes.Android_Mono))
            {
                downloadurl = downloadurl.Substring(0, downloadurl.LastIndexOf("/"));
                downloadurl = $"{downloadurl.Substring(0, downloadurl.LastIndexOf("/"))}/TargetSupportInstaller/UnitySetup-Android-Support-for-Editor-{version.FullVersionStr}.exe";
            }

            Logger.Msg($"Downloading {downloadurl}");
            bool was_error = false;

            try
            {
                webClient.DownloadFile(downloadurl, cache_path);
                was_error = !ExtractFilesFromArchive(version);
                Thread.Sleep(1000);
                if (!was_error)
                {
                    ArchiveHandler.CreateZip(temp_folder_path, zip_path);
                }
            }
            catch (Exception x)
            {
                Logger.Error(x.ToString());
                was_error = true;
            }

#if !DEBUG
            Logger.Msg("Cleaning up...");
            if (Directory.Exists(temp_folder_path))
            {
                Directory.Delete(temp_folder_path, true);
            }
            if (File.Exists(cache_path))
            {
                File.Delete(cache_path);
            }

            string payload_path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Payload~");
            if (File.Exists(payload_path))
            {
                File.Delete(payload_path);
            }
#endif

            if (was_error)
            {
                return(false);
            }
            Logger.Msg($"{version.VersionStr} Zip Successfully Created!");
            return(true);
        }