Beispiel #1
0
        public static void Extract(Player p)
        {
            int errors = 0;

            using (FileStream src = File.OpenRead(zipPath)) {
                ZipReader reader = new ZipReader(src);
                reader.FindFooter();
                int entries = reader.FindEntries();
                p.Message("Restoring {0} files", entries);

                for (int i = 0; i < entries; i++)
                {
                    string path = ExtractItem(reader, i, ref errors);
                    if (i > 0 && (i % 100) == 0)
                    {
                        Logger.Log(LogType.SystemActivity, "Restored {0}/{1} files", i, entries);
                    }

                    if (!path.CaselessEq(sqlPath))
                    {
                        continue;
                    }
                    // If DB is in there, they backed it up, meaning they want it restored
                    using (Stream part = reader.GetEntry(i, out path)) {
                        ReplaceDatabase(part);
                    }
                }
            }

            // To make life easier, we reload settings now, to make it less likely to need restart
            Server.LoadAllSettings();
            p.Message("Server restored" + (errors > 0 ? " with errors. May be a partial restore" : ""));
            p.Message("It is recommended that you restart the server, although this is not required.");
        }
Beispiel #2
0
        static string ExtractItem(ZipReader reader, int i, ref int errors)
        {
            string path;

            using (Stream part = reader.GetEntry(i, out path)) {
                // old server backup used to URI encode files
                path = Uri.UnescapeDataString(path);

                try {
                    Extract(part, path); return(path);
                } catch {
                    try {
                        string dir = Path.GetDirectoryName(path);
                        Directory.CreateDirectory(dir);
                        Extract(part, path); return(path);
                    } catch (IOException e) {
                        Logger.LogError(e);
                        Logger.Log(LogType.Warning, "%WError extracting {0}, continuing with rest.", path);
                        errors++;
                        return("");
                    }
                }
            }
        }