Example #1
0
        public static void FindFEZ()
        {
            string path;

            if ((path = FezFinder.GetSteamPath()) != null)
            {
                try {
                    InstallerWindow.Instance.ExeSelected(path, " [auto - Steam]");
                } catch (Exception e) {
                    Console.WriteLine(e.ToString());
                }
            }
            else if (false)
            {
                //TODO check other paths
                //How does GOG handle FEZ?
            }
            else
            {
                InstallerWindow.Instance.ExeSelected(null);
            }
        }
Example #2
0
        public static bool UnzipMod(this InstallerWindow ins, Stream zs)
        {
            string platform = "";
            string os       = FezFinder.GetPlatform().ToString().ToLower();

            if (os.Contains("win"))
            {
                platform = "win32";
            }
            else if (os.Contains("mac") || os.Contains("osx"))
            {
                platform = "osx";
            }
            else if (os.Contains("lin") || os.Contains("unix"))
            {
                platform = IntPtr.Size == 4 ? "lib" : /*== 8*/ "lib64";
            }

            string prefix = "FEZMOD";
            int    v      = int.Parse(ins.FezVersion.Substring(2));

            if (12 <= v)
            {
                prefix += "-FNA";
                ins.LogLine("FEZ 1.12 has switched from MonoGame to FNA.");
                ins.LogLine("Make sure the version you've picked is supported!");
            }
            prefix += "/";

            string pathFez = ins.ExeMod.Dir.FullName;

            ins.Log("Checking for ").Log(prefix).LogLine("...");

            using (ZipArchive zip = new ZipArchive(zs, ZipArchiveMode.Read)) {
                int prefixCount   = 0;
                int fallbackCount = 0;
                int noneCount     = 0;
                ins.InitProgress("Scanning ZIP", zip.Entries.Count);
                for (int i = 0; i < zip.Entries.Count; i++)
                {
                    ins.SetProgress(i);
                    ZipArchiveEntry entry = zip.Entries[i];
                    ins.Log("Entry: ").Log(entry.FullName).Log(": ").Log(entry.Length.ToString()).LogLine(" bytes");

                    if (entry.FullName == "InstallerVersion.txt")
                    {
                        ins.LogLine("Found version file.");

                        using (Stream s = entry.Open()) {
                            using (StreamReader sr = new StreamReader(s)) {
                                Version minv = new Version(sr.ReadLine().Trim());
                                if (InstallerWindow.Version < minv)
                                {
                                    ins.LogLine("There's a new FEZMod Installer version!");
                                    ins.LogLine("Visit https://fezmod.xyz/#download to download it.");
                                    ins.Log("(Minimum installer version for this FEZMod version: ").LogLine(minv.ToString()).Log(")");
                                    return(false);
                                }
                                if (new Version(16, 5, 10) <= minv)
                                {
                                    ins.LogLine("Blacklisting FEZMod.Speedrun as it's obsolete and causes upgrading issues");
                                    Blacklist.Add("FEZ.Speedrun.mm.dll");
                                }
                            }
                        }

                        continue;
                    }

                    string entryName = entry.FullName;
                    if (entry.FullName.StartsWith(prefix))
                    {
                        prefixCount++;
                    }
                    else if (entry.FullName.StartsWith("FEZMOD/"))
                    {
                        fallbackCount++;
                    }
                    else
                    {
                        noneCount++;
                    }
                }

                if (0 < prefixCount)
                {
                    ins.Log(prefix).LogLine(" found.");
                    ins.InitProgress("Extracting ZIP", prefixCount);
                }
                else if (0 == prefixCount && 0 < fallbackCount)
                {
                    ins.Log("Didn't find ").Log(prefix).LogLine(" - HALT THE GEARS!");
                    ins.EndProgress("Halted.").SetProgress(0);
                    return(false);
                }
                else
                {
                    ins.LogLine("Is this even a FEZMod ZIP? uh...");
                    prefix = "";
                    ins.InitProgress("Extracting ZIP", noneCount);
                }

                int extracted = 0;
                for (int i = 0; i < zip.Entries.Count; i++)
                {
                    ZipArchiveEntry entry = zip.Entries[i];
                    if (!entry.FullName.StartsWith(prefix) || entry.FullName == prefix)
                    {
                        continue;
                    }
                    ins.SetProgress(++extracted);

                    string entryName = entry.FullName.Substring(prefix.Length);

                    if (entryName.StartsWith("LIBS/"))
                    {
                        entryName = entryName.Substring(5);
                        if (!entryName.StartsWith(platform + "/"))
                        {
                            continue;
                        }
                        entryName = entryName.Substring(platform.Length + 1);
                    }

                    entryName = entryName.Replace('/', Path.DirectorySeparatorChar);

                    string path = Path.Combine(pathFez, entryName);
                    ins.Log("Extracting: ").Log(entry.FullName).Log(" -> ").LogLine(path);
                    if (entry.Length == 0 && entry.CompressedLength == 0)
                    {
                        Directory.CreateDirectory(path);
                    }
                    else
                    {
                        entry.ExtractToFile(path, true);
                    }
                }
                ins.EndProgress("Extracted ZIP.");
            }

            return(true);
        }