Ejemplo n.º 1
0
        public override bool func_22101_a(string s, IProgressUpdate iprogressupdate)
        {
            iprogressupdate.setLoadingProgress(0);
            var arraylist  = new ArrayList();
            var arraylist1 = new ArrayList();
            var arraylist2 = new ArrayList();
            var arraylist3 = new ArrayList();
            var file       = new File(field_22106_a, s);
            var file1      = new File(file, "DIM-1");

            [email protected]("Scanning folders...");
            func_22108_a(file, arraylist, arraylist1);
            if (file1.exists())
            {
                func_22108_a(file1, arraylist2, arraylist3);
            }
            int i = arraylist.size() + arraylist2.size() + arraylist1.size() + arraylist3.size();

            [email protected](
                (new StringBuilder()).append("Total conversion count is ").append(i).toString());
            func_22107_a(file, arraylist, 0, i, iprogressupdate);
            func_22107_a(file1, arraylist2, arraylist.size(), i, iprogressupdate);
            WorldInfo worldinfo = func_22103_b(s);

            worldinfo.func_22191_a(19132);
            ISaveHandler isavehandler = func_22105_a(s, false);

            isavehandler.func_22094_a(worldinfo);
            func_22109_a(arraylist1, arraylist.size() + arraylist2.size(), i, iprogressupdate);
            if (file1.exists())
            {
                func_22109_a(arraylist3, arraylist.size() + arraylist2.size() + arraylist1.size(), i, iprogressupdate);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool saveChunks(bool flag, IProgressUpdate iprogressupdate)
        {
            int i = 0;

            for (int j = 0; j < field_727_f.size(); j++)
            {
                var chunk = (Chunk)field_727_f.get(j);
                if (flag && !chunk.neverSave)
                {
                    func_375_a(chunk);
                }
                if (!chunk.needsSaving(flag))
                {
                    continue;
                }
                func_373_b(chunk);
                chunk.isModified = false;
                if (++i == 24 && !flag)
                {
                    return(false);
                }
            }

            if (flag)
            {
                if (field_729_d == null)
                {
                    return(true);
                }
                field_729_d.saveExtraData();
            }
            return(true);
        }
Ejemplo n.º 3
0
        public string UpdateFile(Schema.File fileNode, string localFileNameExplicit, IProgressUpdate progress)
        {
            string localFile =
                localFileNameExplicit == null
                                ? GetLocalFileName(fileNode)
                : localFileNameExplicit;

            return(UpdateFile(fileNode.Path, localFile, fileNode.Archived, progress));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts the specified map to the new map format. Args: worldName, loadingScreen
        /// </summary>
        public override bool ConvertMapFormat(string par1Str, IProgressUpdate par2IProgressUpdate)
        {
            par2IProgressUpdate.SetLoadingProgress(0);
            List <string> arraylist  = new List <string>();
            List <string> arraylist1 = new List <string>();
            List <string> arraylist2 = new List <string>();
            string        file       = IOPath.Combine(SavesDirectory, par1Str);
            string        file1      = IOPath.Combine(file, "DIM-1");
            string        file2      = IOPath.Combine(file, "DIM1");

            Console.WriteLine("Scanning folders...");
            Func_48432_a(file, arraylist);

            if (File.Exists(file1))
            {
                Func_48432_a(file1, arraylist1);
            }

            if (File.Exists(file2))
            {
                Func_48432_a(file2, arraylist2);
            }

            int i = arraylist.Count + arraylist1.Count + arraylist2.Count;

            Console.WriteLine((new StringBuilder()).Append("Total conversion count is ").Append(i).ToString());
            WorldInfo worldinfo = GetWorldInfo(par1Str);
            object    obj       = null;

            if (worldinfo.GetTerrainType() == WorldType.FLAT)
            {
                obj = new WorldChunkManagerHell(BiomeGenBase.Plains, 0.5F, 0.5F);
            }
            else
            {
                obj = new WorldChunkManager(worldinfo.GetSeed(), worldinfo.GetTerrainType());
            }

            Func_48428_a(IOPath.Combine(file, "region"), arraylist, ((WorldChunkManager)(obj)), 0, i, par2IProgressUpdate);
            Func_48428_a(IOPath.Combine(file1, "region"), arraylist1, new WorldChunkManagerHell(BiomeGenBase.Hell, 1.0F, 0.0F), arraylist.Count, i, par2IProgressUpdate);
            Func_48428_a(IOPath.Combine(file2, "region"), arraylist2, new WorldChunkManagerHell(BiomeGenBase.Sky, 0.5F, 0.0F), arraylist.Count + arraylist1.Count, i, par2IProgressUpdate);
            worldinfo.SetSaveVersion(19133);

            if (worldinfo.GetTerrainType() == WorldType.DEFAULT_1_1)
            {
                worldinfo.SetTerrainType(WorldType.DEFAULT);
            }

            createFile(par1Str);
            ISaveHandler isavehandler = GetSaveLoader(par1Str, false);

            isavehandler.SaveWorldInfo(worldinfo);
            return(true);
        }
Ejemplo n.º 5
0
        public bool saveChunks(bool flag, IProgressUpdate iprogressupdate)
        {
            int i = 0;
            int j = 0;

            if (iprogressupdate != null)
            {
                for (int k = 0; k < chunks.Length; k++)
                {
                    if (chunks[k] != null && chunks[k].needsSaving(flag))
                    {
                        j++;
                    }
                }
            }
            int l = 0;

            for (int i1 = 0; i1 < chunks.Length; i1++)
            {
                if (chunks[i1] == null)
                {
                    continue;
                }
                if (flag && !chunks[i1].neverSave)
                {
                    saveExtraChunkData(chunks[i1]);
                }
                if (!chunks[i1].needsSaving(flag))
                {
                    continue;
                }
                saveChunk(chunks[i1]);
                chunks[i1].isModified = false;
                if (++i == 2 && !flag)
                {
                    return(false);
                }
                if (iprogressupdate != null && ++l % 10 == 0)
                {
                    iprogressupdate.setLoadingProgress((l * 100) / j);
                }
            }

            if (flag)
            {
                if (chunkLoader == null)
                {
                    return(true);
                }
                chunkLoader.saveExtraData();
            }
            return(true);
        }
Ejemplo n.º 6
0
        private void func_22109_a(ArrayList arraylist, int i, int j, IProgressUpdate iprogressupdate)
        {
            int k;

            for (Iterator iterator = arraylist.iterator(); iterator.hasNext(); iprogressupdate.setLoadingProgress(k))
            {
                var    file  = (File)iterator.next();
                File[] afile = file.listFiles();
                func_22104_a(afile);
                file.delete();
                i++;
                k = (int)Math.round((100D * i) / j);
            }
        }
Ejemplo n.º 7
0
        private void UpdateWorkerThread(object status)
        {
            KeyValuePair <UpdateObject, IProgressUpdate> data = (KeyValuePair <UpdateObject, IProgressUpdate>)status;
            UpdateObject    module = data.Key;
            IProgressUpdate ipu    = data.Value;

            try
            {
                module.Update(updater, tangra3Path, acceptBetaUpdates, ipu);
            }
            catch (Exception ex)
            {
                ipu.OnError(ex);
            }
        }
Ejemplo n.º 8
0
        public override void Update(Updater updater, string occuRecPath, bool acceptBetaUpdates, IProgressUpdate progress)
        {
            string newVerFileLocalFileName = System.IO.Path.GetFullPath(System.IO.Path.GetTempPath() + "\\OccuRecUpdate.exe");

            if (System.IO.File.Exists(newVerFileLocalFileName))
                System.IO.File.Delete(newVerFileLocalFileName);

            // Download the new OccuRecUpdate version under newVerFileLocalFileName
            string fileLocation = null;
            if (string.IsNullOrEmpty(ArchivedPath))
                fileLocation = Path;
            else
                fileLocation = ArchivedPath;

            try
            {
                progress.RefreshMainForm();
                updater.UpdateFile(fileLocation, newVerFileLocalFileName, !string.IsNullOrEmpty(ArchivedPath), progress);
            }
            catch (WebException wex)
            {
                progress.OnError(wex);

                return;
            }

            string selfUpdaterExecutable = Config.Instance.PrepareOccuRecSelfUpdateTempFile(occuRecPath, acceptBetaUpdates, newVerFileLocalFileName);

            using (Stream selfUpdater = Shared.AssemblyHelper.GetEmbededResourceStreamThatClientMustDispose("OccuRecUpdate.SelfUpdate", "OccuRecSelfUpdate.bin"))
            {
                byte[] buffer = new byte[selfUpdater.Length];
                selfUpdater.Read(buffer, 0, buffer.Length);
                System.IO.File.WriteAllBytes(selfUpdaterExecutable, buffer);
            }

            // Run the copyFileName passing as argument current process ID and then terminate the current process fast!
            Process currProcess = Process.GetCurrentProcess();
            ProcessStartInfo pi = new ProcessStartInfo(selfUpdaterExecutable, currProcess.Id.ToString());

            if (System.Environment.OSVersion.Version.Major > 5)
                // UAC Elevate as Administrator for Windows Vista, Win7 and later
                pi.Verb = "runas";

            pi.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(pi);

            currProcess.Kill();
        }
Ejemplo n.º 9
0
        ///<summary>
        /// Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
        /// Return true if all chunks have been saved.
        ///</summary>
        public bool SaveChunks(bool par1, IProgressUpdate par2IProgressUpdate)
        {
            int i = 0;

            for (int j = 0; j < chunkList.Count; j++)
            {
                Chunk chunk = chunkList[j];

                if (par1)
                {
                    SaveChunkExtraData(chunk);
                }

                if (!chunk.NeedsSaving(par1))
                {
                    continue;
                }

                SaveChunkData(chunk);
                chunk.IsModified = false;

                if (++i == 24 && !par1)
                {
                    return(false);
                }
            }

            if (par1)
            {
                if (chunkLoader == null)
                {
                    return(true);
                }

                chunkLoader.SaveExtraData();
            }

            return(true);
        }
Ejemplo n.º 10
0
        private void func_22107_a(File file, ArrayList arraylist, int i, int j, IProgressUpdate iprogressupdate)
        {
            Collections.sort(arraylist);
            var abyte0 = new byte[4096];
            int i1;

            for (Iterator iterator = arraylist.iterator(); iterator.hasNext(); iprogressupdate.setLoadingProgress(i1))
            {
                var        filematcher = (FileMatcher)iterator.next();
                int        k           = filematcher.func_22205_b();
                int        l           = filematcher.func_22204_c();
                RegionFile regionfile  = RegionFileCache.func_22123_a(file, k, l);
                if (!regionfile.isChunkSaved(k & 0x1f, l & 0x1f))
                {
                    try
                    {
                        var datainputstream =
                            new DataInputStream(new GZIPInputStream(new FileInputStream(filematcher.func_22207_a())));
                        DataOutputStream dataoutputstream = regionfile.getChunkDataOutputStream(k & 0x1f, l & 0x1f);
                        for (int j1 = 0; (j1 = datainputstream.read(abyte0)) != -1;)
                        {
                            dataoutputstream.write(abyte0, 0, j1);
                        }

                        dataoutputstream.close();
                        datainputstream.close();
                    }
                    catch (IOException ioexception)
                    {
                        ioexception.printStackTrace();
                    }
                }
                i++;
                i1 = (int)Math.round((100D * i) / j);
            }

            RegionFileCache.func_22122_a();
        }
    /**
     * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
     * Return true if all chunks have been saved.
     */
    public bool saveChunks(bool p_73151_1, IProgressUpdate progressCallback)
    {
        int i = 0;

        for (int j = 0; j < loadedChunks.Count; ++j)
        {
            Chunk chunk = loadedChunks [j];

            if (p_73151_1)
            {
            }

            savaChunkData(chunk);
            ++i;

            if (i == 24 && !p_73151_1)
            {
                return(false);
            }
        }

        return(true);
    }
 ///<summary>
 /// Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
 /// Return true if all chunks have been saved.
 ///</summary>
 public bool SaveChunks(bool par1, IProgressUpdate par2IProgressUpdate)
 {
     return(true);
 }
Ejemplo n.º 13
0
 public bool saveChunks(bool flag, IProgressUpdate iprogressupdate)
 {
     return(true);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
        /// Return true if all chunks have been saved.
        /// </summary>
        public virtual bool SaveChunks(bool par1, IProgressUpdate par2IProgressUpdate)
        {
            int i = 0;
            int j = 0;

            if (par2IProgressUpdate != null)
            {
                for (int k = 0; k < Chunks.Length; k++)
                {
                    if (Chunks[k] != null && Chunks[k].NeedsSaving(par1))
                    {
                        j++;
                    }
                }
            }

            int l = 0;

            for (int i1 = 0; i1 < Chunks.Length; i1++)
            {
                if (Chunks[i1] == null)
                {
                    continue;
                }

                if (par1)
                {
                    SaveExtraChunkData(Chunks[i1]);
                }

                if (!Chunks[i1].NeedsSaving(par1))
                {
                    continue;
                }

                SaveChunk(Chunks[i1]);
                Chunks[i1].IsModified = false;

                if (++i == 2 && !par1)
                {
                    return(false);
                }

                if (par2IProgressUpdate != null && ++l % 10 == 0)
                {
                    par2IProgressUpdate.SetLoadingProgress((l * 100) / j);
                }
            }

            if (par1)
            {
                if (ChunkLoader == null)
                {
                    return(true);
                }

                ChunkLoader.SaveExtraData();
            }

            return(true);
        }
Ejemplo n.º 15
0
 /**
  * Two modes of operation: if passed true, save all Chunks in one go.  If passed false, save up to two chunks.
  * Return true if all chunks have been saved.
  */
 public bool saveChunks(bool p_73151_1_, IProgressUpdate progressCallback)
 {
     return(true);
 }
Ejemplo n.º 16
0
        public bool saveChunks(bool flag, IProgressUpdate iprogressupdate)
        {
            int i = 0;
            int j = 0;
            if (iprogressupdate != null)
            {
                for (int k = 0; k < chunks.Length; k++)
                {
                    if (chunks[k] != null && chunks[k].needsSaving(flag))
                    {
                        j++;
                    }
                }
            }
            int l = 0;
            for (int i1 = 0; i1 < chunks.Length; i1++)
            {
                if (chunks[i1] == null)
                {
                    continue;
                }
                if (flag && !chunks[i1].neverSave)
                {
                    saveExtraChunkData(chunks[i1]);
                }
                if (!chunks[i1].needsSaving(flag))
                {
                    continue;
                }
                saveChunk(chunks[i1]);
                chunks[i1].isModified = false;
                if (++i == 2 && !flag)
                {
                    return false;
                }
                if (iprogressupdate != null && ++l%10 == 0)
                {
                    iprogressupdate.setLoadingProgress((l*100)/j);
                }
            }

            if (flag)
            {
                if (chunkLoader == null)
                {
                    return true;
                }
                chunkLoader.saveExtraData();
            }
            return true;
        }
Ejemplo n.º 17
0
 public void saveWorld(bool flag, IProgressUpdate iprogressupdate)
 {
     if (!chunkProvider.func_364_b())
     {
         return;
     }
     if (iprogressupdate != null)
     {
         iprogressupdate.func_438_a("Saving level");
     }
     saveLevel();
     if (iprogressupdate != null)
     {
         iprogressupdate.displayLoadingString("Saving chunks");
     }
     chunkProvider.saveChunks(flag, iprogressupdate);
 }
Ejemplo n.º 18
0
 public virtual bool func_22101_a(string s, IProgressUpdate iprogressupdate)
 {
     return(false);
 }
Ejemplo n.º 19
0
 public bool saveChunks(bool flag, IProgressUpdate iprogressupdate)
 {
     return true;
 }
Ejemplo n.º 20
0
 public string UpdateFile(Schema.File fileNode, IProgressUpdate progress)
 {
     return UpdateFile(fileNode, null, progress);
 }
Ejemplo n.º 21
0
        public string UpdateFile(string location, string localFile, bool shouldUnzip, IProgressUpdate progress)
        {
            Uri fileUri = new Uri(Config.Instance.UpdateLocation + "/" + location.TrimStart(new char[] { '/' }));

            progress.UpdateProgress(string.Format("Downloading {0} ...", Path.GetFileName(localFile)), -1);

            bool      allGood          = false;
            int       attempts         = 0;
            Exception fileDelException = null;

            do
            {
                try
                {
                    if (System.IO.File.Exists(localFile))
                    {
                        // throws access denied: -2147024891
                        System.IO.File.Delete(localFile);
                    }

                    allGood          = true;
                    fileDelException = null;
                }
                catch (Exception ex)
                {
                    fileDelException = ex;
                    System.Threading.Thread.Sleep(500);
                }

                attempts++;
            }while (!allGood && attempts < 10);

            if (fileDelException != null)
            {
                System.Windows.Forms.MessageBox.Show(
                    "There was a problem upgrading " + SharedUpdateConstants.MAIN_PROGRAM_NAME + "\r\n\r\n" + fileDelException.GetType().ToString() + " : " + fileDelException.Message +
                    "\r\n\r\nPlease note that the update process needs to be run by an administrator. Stop all running copies of " + SharedUpdateConstants.MAIN_PROGRAM_NAME + " and then manually run:\r\n\r\n" +
                    Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "\\" + SharedUpdateConstants.MAIN_UPDATER_EXECUTABLE_NAME) +
                    "\r\n\r\nYou can also use Right-Click and then use 'Run as ...' and specify a user with administrative previlegies.",
                    "Error Upgrading",
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error);

                Process.GetCurrentProcess().Kill();
            }

            if (!Directory.Exists(Path.GetDirectoryName(localFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localFile));
            }


            if (fileUri.IsFile)
            {
                System.IO.File.Copy(fileUri.LocalPath, localFile);
            }
            else
            {
                HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(fileUri);
                httpRequest.Method  = "GET";
                httpRequest.Timeout = 600000;                 //600 sec = 10 min

                HttpWebResponse response = null;

                try
                {
                    response = (HttpWebResponse)httpRequest.GetResponse();

                    Stream streamResponse = response.GetResponseStream();
                    long   totalBytes     = response.ContentLength;

                    try
                    {
                        using (BinaryReader reader = new BinaryReader(streamResponse))
                            using (BinaryWriter writer = new BinaryWriter(new FileStream(localFile, FileMode.Create)))
                            {
                                byte[] chunk = null;
                                do
                                {
                                    chunk = reader.ReadBytes(1024);
                                    //TODO: Send back info on the download progress with the bytes read and total bytes
                                    writer.Write(chunk);
                                }while (chunk != null && chunk.Length == 1024);

                                writer.Flush();
                            }
                    }
                    finally
                    {
                        streamResponse.Close();
                    }
                }
                finally
                {
                    // Close response
                    if (response != null)
                    {
                        response.Close();
                    }
                }
            }

            //TODO: Set the full content downloaded, hide the byte download progress label

            if (shouldUnzip)
            {
                string tempOutputDir = Path.ChangeExtension(Path.GetTempFileName(), "");
                Directory.CreateDirectory(tempOutputDir);
                try
                {
                    ZipUnzip.UnZip(localFile, tempOutputDir, true);
                    string[] files = Directory.GetFiles(tempOutputDir);
                    System.IO.File.Copy(files[0], localFile, true);
                    System.IO.File.Delete(files[0]);
                }
                finally
                {
                    Directory.Delete(tempOutputDir, true);
                }
            }

            return(localFile);
        }
Ejemplo n.º 22
0
        public bool saveChunks(bool flag, IProgressUpdate iprogressupdate)
        {
            int i = 0;
            for (int j = 0; j < field_727_f.size(); j++)
            {
                var chunk = (Chunk) field_727_f.get(j);
                if (flag && !chunk.neverSave)
                {
                    func_375_a(chunk);
                }
                if (!chunk.needsSaving(flag))
                {
                    continue;
                }
                func_373_b(chunk);
                chunk.isModified = false;
                if (++i == 24 && !flag)
                {
                    return false;
                }
            }

            if (flag)
            {
                if (field_729_d == null)
                {
                    return true;
                }
                field_729_d.saveExtraData();
            }
            return true;
        }
Ejemplo n.º 23
0
 public string UpdateFile(Schema.File fileNode, IProgressUpdate progress)
 {
     return(UpdateFile(fileNode, null, progress));
 }
Ejemplo n.º 24
0
        public override void Update(Updater updater, string tangra3Path, bool acceptBetaUpdates, IProgressUpdate progress)
        {
            string newVerFileLocalFileName = System.IO.Path.GetFullPath(System.IO.Path.GetTempPath() + "\\" + SharedUpdateConstants.MAIN_UPDATER_EXECUTABLE_NAME);

            if (System.IO.File.Exists(newVerFileLocalFileName))
            {
                System.IO.File.Delete(newVerFileLocalFileName);
            }

            // Download the new AutoUpdate version under newVerFileLocalFileName
            string fileLocation = null;

            if (string.IsNullOrEmpty(ArchivedPath))
            {
                fileLocation = Path;
            }
            else
            {
                fileLocation = ArchivedPath;
            }

            try
            {
                progress.RefreshMainForm();
                updater.UpdateFile(fileLocation, newVerFileLocalFileName, !string.IsNullOrEmpty(ArchivedPath), progress);
            }
            catch (WebException wex)
            {
                progress.OnError(wex);

                return;
            }

            string selfUpdaterExecutable = Config.Instance.PrepareTangra3SelfUpdateTempFile(tangra3Path, acceptBetaUpdates, newVerFileLocalFileName);

            using (Stream selfUpdater = Shared.AssemblyHelper.GetEmbededResourceStreamThatClientMustDispose("AutoUpdate.SelfUpdate", "AutoUpdateSelfUpdate.bin"))
            {
                byte[] buffer = new byte[selfUpdater.Length];
                selfUpdater.Read(buffer, 0, buffer.Length);
                System.IO.File.WriteAllBytes(selfUpdaterExecutable, buffer);
            }

            // Run the copyFileName passing as argument current process ID and then terminate the current process fast!
            var currProcess = Process.GetCurrentProcess();
            var pi          = new ProcessStartInfo(selfUpdaterExecutable, currProcess.Id.ToString());

            if (System.Environment.OSVersion.Version.Major > 5)
            {
                // UAC Elevate as Administrator for Windows Vista, Win7 and later
                pi.Verb = "runas";
            }

            pi.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(pi);

            currProcess.Kill();
        }
Ejemplo n.º 25
0
        private void Func_48430_a(string par1File, string par2File, WorldChunkManager par3WorldChunkManager, int par4, int par5, IProgressUpdate par6IProgressUpdate)
        {
            try
            {
                FileInfo   file        = new FileInfo(par2File);
                string     s           = file.Name;
                RegionFile regionfile  = new RegionFile(par2File);
                RegionFile regionfile1 = new RegionFile(IOPath.Combine(par1File, (new StringBuilder()).Append(s.Substring(0, s.Length - ".mcr".Length)).Append(".mca").ToString()));

                for (int i = 0; i < 32; i++)
                {
                    for (int j = 0; j < 32; j++)
                    {
                        if (!regionfile.IsChunkSaved(i, j) || regionfile1.IsChunkSaved(i, j))
                        {
                            continue;
                        }

                        Stream datainputstream = regionfile.GetChunkFileStream(i, j);

                        if (datainputstream == null)
                        {
                            Console.WriteLine("Failed to fetch input stream");
                        }
                        else
                        {
                            NBTTagCompound nbttagcompound = CompressedStreamTools.Read(new BinaryReader(datainputstream));
                            datainputstream.Close();

                            NBTTagCompound nbttagcompound1 = nbttagcompound.GetCompoundTag("Level");

                            AnvilConverterData anvilconverterdata = ChunkLoader.Load(nbttagcompound1);
                            NBTTagCompound     nbttagcompound2    = new NBTTagCompound();
                            NBTTagCompound     nbttagcompound3    = new NBTTagCompound();
                            nbttagcompound2.SetTag("Level", nbttagcompound3);

                            ChunkLoader.ConvertToAnvilFormat(anvilconverterdata, nbttagcompound3, par3WorldChunkManager);

                            Stream dataoutputstream = regionfile1.GetChunkDataOutputStream(i, j);
                            CompressedStreamTools.Write(nbttagcompound2, new BinaryWriter(dataoutputstream));
                            dataoutputstream.Close();
                        }
                    }

                    int k = (int)Math.Round((100D * (double)(par4 * 1024)) / (double)(par5 * 1024));
                    int l = (int)Math.Round((100D * (double)((i + 1) * 32 + par4 * 1024)) / (double)(par5 * 1024));

                    if (l > k)
                    {
                        par6IProgressUpdate.SetLoadingProgress(l);
                    }
                }

                regionfile.Close();
                regionfile1.Close();
            }
            catch (IOException ioexception)
            {
                Utilities.LogException(ioexception);
            }
        }
Ejemplo n.º 26
0
        public string UpdateFile(Schema.File fileNode, string localFileNameExplicit, IProgressUpdate progress)
        {
            string localFile =
                localFileNameExplicit == null
                ? GetLocalFileName(fileNode)
                : localFileNameExplicit;

            return UpdateFile(fileNode.Path, localFile, fileNode.Archived, progress);
        }
Ejemplo n.º 27
0
        public virtual void Update(Updater updater, string occuRecPath, bool acceptBetaUpdates, IProgressUpdate progress)
        {
            foreach (Schema.File fileToUpdate in AllFiles)
            {
                try
                {
                    string localFilePath;

                    if (fileToUpdate.Action == "DeleteIfExists")
                    {
                        localFilePath = updater.GetLocalFileName(fileToUpdate);
                        if (System.IO.File.Exists(localFilePath))
                        {
                            try
                            {
                                System.IO.File.Delete(localFilePath);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(ex);
                            }
                        }
                        return;
                    }

                    localFilePath = updater.UpdateFile(fileToUpdate, progress);

                    OnFileUpdated(fileToUpdate, localFilePath);

                    if (!string.IsNullOrEmpty(fileToUpdate.Action))
                        ExecutePostUpdateAction(fileToUpdate, localFilePath);
                }
                catch (Exception ex)
                {
                    progress.OnError(ex);
                    return;
                }
            }
        }
Ejemplo n.º 28
0
 private void Func_48428_a(string par1File, List <string> par2ArrayList, WorldChunkManager par3WorldChunkManager, int par4, int par5, IProgressUpdate par6IProgressUpdate)
 {
     for (int i = 0; i < par2ArrayList.Count; i++)
     {
         par6IProgressUpdate.SetLoadingProgress(i);
         string file = par2ArrayList[i];
         Func_48430_a(par1File, file, par3WorldChunkManager, par4, par5, par6IProgressUpdate);
         par4++;
         i = (int)Math.Round((100D * (double)par4) / (double)par5);
     }
 }
Ejemplo n.º 29
0
        public string UpdateFile(string location, string localFile, bool shouldUnzip, IProgressUpdate progress)
        {
            Uri fileUri = new Uri(Config.Instance.UpdateLocation + "/" + location.TrimStart(new char[] { '/' }));

            progress.UpdateProgress(string.Format("Downloading {0} ...", Path.GetFileName(localFile)), -1);

            HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(fileUri);
            httpRequest.Method = "GET";
            httpRequest.Timeout = 600000; //600 sec = 10 min

            HttpWebResponse response = null;

            try
            {
                response = (HttpWebResponse)httpRequest.GetResponse();

                Stream streamResponse = response.GetResponseStream();
                long totalBytes = response.ContentLength;

                try
                {
                    bool allGood = false;
                    int attempts = 0;
                    Exception fileDelException = null;
                    do
                    {
                        try
                        {
                            if (System.IO.File.Exists(localFile))
                                // throws access denied: -2147024891
                                System.IO.File.Delete(localFile);

                            allGood = true;
                            fileDelException = null;
                        }
                        catch (Exception ex)
                        {
                            fileDelException = ex;
                            System.Threading.Thread.Sleep(500);
                        }

                        attempts++;
                    }
                    while (!allGood && attempts < 10);

                    if (fileDelException != null)
                    {
                        System.Windows.Forms.MessageBox.Show(
                            "There was a problem upgrading OccuRec\r\n\r\n" + fileDelException.GetType().ToString() + " : " + fileDelException.Message +
                            "\r\n\r\nPlease note that the update process needs to be run by an administrator. Stop all running copies of OccuRec and then manually run:\r\n\r\n" +
                            Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + "\\OccuRecUpdate.exe") +
                            "\r\n\r\nYou can also use Right-Click and then use 'Run as ...' and specify a user with administrative previlegies.",
                            "Error Upgrading",
                            System.Windows.Forms.MessageBoxButtons.OK,
                            System.Windows.Forms.MessageBoxIcon.Error);

                        Process.GetCurrentProcess().Kill();
                    }

                    if (!Directory.Exists(Path.GetDirectoryName(localFile)))
                        Directory.CreateDirectory(Path.GetDirectoryName(localFile));

                    using (BinaryReader reader = new BinaryReader(streamResponse))
                    using (BinaryWriter writer = new BinaryWriter(new FileStream(localFile, FileMode.Create)))
                    {
                        byte[] chunk = null;
                        do
                        {
                            chunk = reader.ReadBytes(1024);
                            //TODO: Send back info on the download progress with the bytes read and total bytes
                            writer.Write(chunk);
                        }
                        while (chunk != null && chunk.Length == 1024);

                        writer.Flush();
                    }

                    //TODO: Set the full content downloaded, hide the byte download progress label

                    if (shouldUnzip)
                    {
                        string tempOutputDir = Path.ChangeExtension(Path.GetTempFileName(), "");
                        Directory.CreateDirectory(tempOutputDir);
                        try
                        {
                            ZipUnzip.UnZip(localFile, tempOutputDir, true);
                            string[] files = Directory.GetFiles(tempOutputDir);
                            System.IO.File.Copy(files[0], localFile, true);
                            System.IO.File.Delete(files[0]);
                        }
                        finally
                        {
                            Directory.Delete(tempOutputDir, true);
                        }
                    }
                }
                finally
                {
                    streamResponse.Close();
                }

                return localFile;

            }
            finally
            {
                // Close response
                if (response != null)
                    response.Close();
            }
        }
Ejemplo n.º 30
0
        public virtual void Update(Updater updater, string tangra3Path, bool acceptBetaUpdates, IProgressUpdate progress)
        {
            foreach (Schema.File fileToUpdate in AllFiles)
            {
                try
                {
                    string localFilePath;

                    if (fileToUpdate.Action == "DeleteIfExists")
                    {
                        localFilePath = updater.GetLocalFileName(fileToUpdate);
                        if (System.IO.File.Exists(localFilePath))
                        {
                            try
                            {
                                System.IO.File.Delete(localFilePath);
                            }
                            catch (Exception ex)
                            {
                                Trace.WriteLine(ex);
                            }
                        }
                        return;
                    }

                    localFilePath = updater.UpdateFile(fileToUpdate, progress);

                    OnFileUpdated(fileToUpdate, localFilePath);

                    if (!string.IsNullOrEmpty(fileToUpdate.Action))
                    {
                        ExecutePostUpdateAction(fileToUpdate, localFilePath);
                    }
                }
                catch (Exception ex)
                {
                    progress.OnError(ex);
                    return;
                }
            }
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Converts the specified map to the new map format. Args: worldName, loadingScreen
 /// </summary>
 public virtual bool ConvertMapFormat(string par1Str, IProgressUpdate par2IProgressUpdate)
 {
     return(false);
 }