Exemplo n.º 1
0
        public static void PutOrPost(bool isPost, string address, Dictionary <string, string> parameters, Dictionary <string, string> headers, Stream data, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure)
        {
            byte[]    responseData = default(byte[]);
            Exception e            = default(Exception);

            Task.Run(async delegate
            {
                _ = 5;
                try
                {
                    if (!IsInternetConnectionAvailable())
                    {
                        throw new InvalidOperationException("Internet connection is unavailable.");
                    }
                    using (HttpClient client = new HttpClient())
                    {
                        Dictionary <string, string> dictionary = new Dictionary <string, string>();
                        if (headers != null)
                        {
                            foreach (KeyValuePair <string, string> header in headers)
                            {
                                if (!client.DefaultRequestHeaders.TryAddWithoutValidation(header.Key, header.Value))
                                {
                                    dictionary.Add(header.Key, header.Value);
                                }
                            }
                        }
                        System.Uri requestUri   = (parameters != null && parameters.Count > 0) ? new System.Uri($"{address}?{UrlParametersToString(parameters)}") : new System.Uri(address);
                        HttpContent httpContent = (progress != null) ? ((HttpContent) new ProgressHttpContent(data, progress)) : ((HttpContent) new StreamContent(data));
                        foreach (KeyValuePair <string, string> item in dictionary)
                        {
                            httpContent.Headers.Add(item.Key, item.Value);
                        }
                        HttpResponseMessage responseMessage = isPost ? ((progress == null) ? (await client.PostAsync(requestUri, httpContent)) : (await client.PostAsync(requestUri, httpContent, progress.CancellationToken))) : ((progress == null) ? (await client.PutAsync(requestUri, httpContent)) : (await client.PutAsync(requestUri, httpContent, progress.CancellationToken)));
                        await VerifyResponse(responseMessage);
                        responseData = await responseMessage.Content.ReadAsByteArrayAsync();
                        if (success != null)
                        {
                            Dispatcher.Dispatch(delegate
                            {
                                success(responseData);
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    e = ex;
                    Log.Error(ExceptionManager.MakeFullErrorMessage(e));
                    if (failure != null)
                    {
                        Dispatcher.Dispatch(delegate
                        {
                            failure(e);
                        });
                    }
                }
            });
        }
Exemplo n.º 2
0
 public static bool IsInternetConnectionAvailable()
 {
     try
     {
         return(((ConnectivityManager)Window.Activity.GetSystemService("connectivity")).ActiveNetworkInfo?.IsConnected ?? false);
     }
     catch (Exception e)
     {
         Log.Warning(ExceptionManager.MakeFullErrorMessage("Could not check internet connection availability.", e));
     }
     return(true);
 }
Exemplo n.º 3
0
        public bool LoadChunkBlocks(TerrainChunk chunk)
        {
            _ = Time.RealTime;
            bool    result  = false;
            Terrain terrain = m_subsystemTerrain.Terrain;
            int     num     = chunk.Origin.X >> 4;
            int     num2    = chunk.Origin.Y >> 4;

            try
            {
                if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out int value))
                {
                    m_stream.Seek(value, SeekOrigin.Begin);
                    ReadChunkHeader(m_stream);
                    int num3 = 0;
                    m_stream.Read(m_buffer, 0, 131072);
                    for (int i = 0; i < 16; i++)
                    {
                        for (int j = 0; j < 16; j++)
                        {
                            int num4 = TerrainChunk.CalculateCellIndex(i, 0, j);
                            for (int k = 0; k < 256; k++)
                            {
                                int num5 = m_buffer[num3++];
                                num5 |= m_buffer[num3++] << 8;
                                chunk.SetCellValueFast(num4++, num5);
                            }
                        }
                    }
                    num3 = 0;
                    m_stream.Read(m_buffer, 0, 1024);
                    for (int l = 0; l < 16; l++)
                    {
                        for (int m = 0; m < 16; m++)
                        {
                            int num6 = m_buffer[num3++];
                            num6 |= m_buffer[num3++] << 8;
                            num6 |= m_buffer[num3++] << 16;
                            num6 |= m_buffer[num3++] << 24;
                            terrain.SetShaftValue(l + chunk.Origin.X, m + chunk.Origin.Y, num6);
                        }
                    }
                    result = true;
                }
            }
            catch (Exception e)
            {
                Log.Error(ExceptionManager.MakeFullErrorMessage($"Error loading data for chunk ({num},{num2}).", e));
            }
            _ = Time.RealTime;
            return(result);
        }
Exemplo n.º 4
0
 public static void LogError(string message, Exception error)
 {
     try
     {
         double realTime = Time.RealTime;
         if (!(realTime - LastSendTime < 15.0))
         {
             LastSendTime = realTime;
             Dictionary <string, string> dictionary = new Dictionary <string, string>();
             dictionary.Add("Platform", VersionsManager.Platform.ToString());
             dictionary.Add("BuildConfiguration", VersionsManager.BuildConfiguration.ToString());
             dictionary.Add("DeviceModel", DeviceManager.DeviceModel);
             dictionary.Add("OSVersion", DeviceManager.OperatingSystemVersion);
             dictionary.Add("Is64bit", (Marshal.SizeOf <IntPtr>() == 8).ToString());
             dictionary.Add("FreeSpace", (Storage.FreeSpace / 1024 / 1024).ToString() + "MB");
             dictionary.Add("TotalAvailableMemory", (Utilities.GetTotalAvailableMemory() / 1024).ToString() + "kB");
             dictionary.Add("RealTime", Time.RealTime.ToString("0.000") + "s");
             dictionary.Add("WindowSize", Window.Size.ToString());
             dictionary.Add("FullErrorMessage", ExceptionManager.MakeFullErrorMessage(message, error));
             dictionary.Add("ExceptionType", error.GetType().ToString());
             dictionary.Add("ExceptionStackTrace", AbbreviateStackTrace(error.StackTrace));
             MemoryStream  memoryStream  = new MemoryStream();
             DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionLevel.Optimal, leaveOpen: true);
             BinaryWriter  binaryWriter  = new BinaryWriter(deflateStream);
             binaryWriter.Write(3735928559u);
             binaryWriter.Write((byte)dictionary.Count);
             foreach (KeyValuePair <string, string> item in dictionary)
             {
                 binaryWriter.Write(item.Key);
                 binaryWriter.Write(item.Value);
             }
             deflateStream.Dispose();
             memoryStream.Position = 0L;
             WebManager.Post(string.Format("{0}:{1}/{2}/{3}/{4}/{5}", "http://quality.kaalus.com", 30099, 1, "Survivalcraft", VersionsManager.Version, "Error"), null, null, memoryStream, null, null, null);
         }
     }
     catch
     {
     }
 }
Exemplo n.º 5
0
        // Replace LoadingScreen.Update
        public override void Update()
        {
            if (!m_loadingStarted)
            {
                m_loadingStarted = true;
            }
            else if (!m_loadingFinished)
            {
                double realTime = Time.RealTime;
                while (!m_pauseLoading && m_index < m_loadActions.Count)
                {
                    try
                    {
                        m_loadActions[m_index++]();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Loading error. Reason: " + ex);
                        if (!m_loadingErrorsSuppressed)
                        {
                            m_pauseLoading = true;
                            DialogsManager.ShowDialog(WidgetsManager.RootWidget, new MessageDialog("Loading Error", ExceptionManager.MakeFullErrorMessage(ex), "OK", "Suppress", delegate(MessageDialogButton b)
                            {
                                switch (b)
                                {
                                case MessageDialogButton.Button1:
                                    m_pauseLoading = false;
                                    break;

                                case MessageDialogButton.Button2:
                                    m_loadingErrorsSuppressed = true;
                                    break;
                                }
                            }));
                        }
                    }
                    if (Time.RealTime - realTime > 0.1)
                    {
                        break;
                    }
                }
                if (m_index >= m_loadActions.Count)
                {
                    m_loadingFinished = true;
                    AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f);
                    ScreensManager.SwitchScreen("MainMenu");
                }
            }
        }
Exemplo n.º 6
0
        public static WorldInfo GetWorldInfo(string directoryName)
        {
            WorldInfo worldInfo = new WorldInfo();

            worldInfo.DirectoryName = directoryName;
            worldInfo.LastSaveTime  = DateTime.MinValue;
            List <string> list = new List <string>();

            RecursiveEnumerateDirectory(directoryName, list, null, null);
            if (list.Count > 0)
            {
                foreach (string item in list)
                {
                    DateTime fileLastWriteTime = Storage.GetFileLastWriteTime(item);
                    if (fileLastWriteTime > worldInfo.LastSaveTime)
                    {
                        worldInfo.LastSaveTime = fileLastWriteTime;
                    }
                    try
                    {
                        worldInfo.Size += Storage.GetFileSize(item);
                    }
                    catch (Exception e2)
                    {
                        Log.Error(ExceptionManager.MakeFullErrorMessage($"Error getting size of file \"{item}\".", e2));
                    }
                }
                string text = Storage.CombinePaths(directoryName, "Project.xml");
                try
                {
                    if (Storage.FileExists(text))
                    {
                        using (Stream stream = Storage.OpenFile(text, OpenFileMode.Read))
                        {
                            XElement xElement = XmlUtils.LoadXmlFromStream(stream, null, throwOnError: true);
                            worldInfo.SerializationVersion = XmlUtils.GetAttributeValue(xElement, "Version", "1.0");
                            VersionsManager.UpgradeProjectXml(xElement);
                            XElement         gameInfoNode     = GetGameInfoNode(xElement);
                            ValuesDictionary valuesDictionary = new ValuesDictionary();
                            valuesDictionary.ApplyOverrides(gameInfoNode);
                            worldInfo.WorldSettings.Load(valuesDictionary);
                            foreach (XElement item2 in (from e in GetPlayersNode(xElement).Elements()
                                                        where XmlUtils.GetAttributeValue <string>(e, "Name") == "Players"
                                                        select e).First().Elements())
                            {
                                PlayerInfo playerInfo = new PlayerInfo();
                                worldInfo.PlayerInfos.Add(playerInfo);
                                XElement xElement2 = (from e in item2.Elements()
                                                      where XmlUtils.GetAttributeValue(e, "Name", string.Empty) == "CharacterSkinName"
                                                      select e).FirstOrDefault();
                                if (xElement2 != null)
                                {
                                    playerInfo.CharacterSkinName = XmlUtils.GetAttributeValue(xElement2, "Value", string.Empty);
                                }
                            }
                            return(worldInfo);
                        }
                    }
                    return(worldInfo);
                }
                catch (Exception e3)
                {
                    Log.Error(ExceptionManager.MakeFullErrorMessage($"Error getting data from project file \"{text}\".", e3));
                    return(worldInfo);
                }
            }
            return(null);
        }
        public override void Update()
        {
            if (this.m_loadingFinished)
            {
                return;
            }
            double realTime = Time.RealTime;

            while (!this.m_pauseLoading)
            {
                if (this.m_index < this.m_loadActions.Count)
                {
                    try
                    {
                        List <Action> loadActions = this.m_loadActions;
                        int           index1      = this.m_index;
                        this.m_index = index1 + 1;
                        int index2 = index1;
                        loadActions[index2]();
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Loading error. Reason: " + ex.Message);
                        if (!this.m_loadingErrorsSuppressed)
                        {
                            this.m_pauseLoading = true;
                            DialogsManager.ShowDialog((Dialog) new MessageDialog("Loading Error", ExceptionManager.MakeFullErrorMessage(ex), "OK", "Suppress", (Action <MessageDialogButton>)(b =>
                            {
                                if (b == MessageDialogButton.Button1)
                                {
                                    this.m_pauseLoading = false;
                                }
                                else
                                {
                                    if (b != MessageDialogButton.Button2)
                                    {
                                        return;
                                    }
                                    this.m_loadingErrorsSuppressed = true;
                                }
                            })));
                        }
                    }
                    if (Time.RealTime - realTime > 0.1)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            if (this.m_index < this.m_loadActions.Count)
            {
                return;
            }
            this.m_loadingFinished = true;
            AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0.0f, 0.0f);
            FrontendManager.StartFadeOutIn((Action)(() => ScreensManager.SwitchScreen("MainMenu")));
        }
Exemplo n.º 8
0
        public void SaveChunkBlocks(TerrainChunk chunk)
        {
            _ = Time.RealTime;
            Terrain terrain = m_subsystemTerrain.Terrain;
            int     num     = chunk.Origin.X >> 4;
            int     num2    = chunk.Origin.Y >> 4;

            try
            {
                bool flag = false;
                if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out int value))
                {
                    m_stream.Seek(value, SeekOrigin.Begin);
                }
                else
                {
                    flag  = true;
                    value = (int)m_stream.Length;
                    m_stream.Seek(value, SeekOrigin.Begin);
                }
                WriteChunkHeader(m_stream, num, num2);
                int num3 = 0;
                for (int i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        int num4 = TerrainChunk.CalculateCellIndex(i, 0, j);
                        for (int k = 0; k < 256; k++)
                        {
                            int cellValueFast = chunk.GetCellValueFast(num4++);
                            m_buffer[num3++] = (byte)cellValueFast;
                            m_buffer[num3++] = (byte)(cellValueFast >> 8);
                        }
                    }
                }
                m_stream.Write(m_buffer, 0, 131072);
                num3 = 0;
                for (int l = 0; l < 16; l++)
                {
                    for (int m = 0; m < 16; m++)
                    {
                        int shaftValue = terrain.GetShaftValue(l + chunk.Origin.X, m + chunk.Origin.Y);
                        m_buffer[num3++] = (byte)shaftValue;
                        m_buffer[num3++] = (byte)(shaftValue >> 8);
                        m_buffer[num3++] = (byte)(shaftValue >> 16);
                        m_buffer[num3++] = (byte)(shaftValue >> 24);
                    }
                }
                m_stream.Write(m_buffer, 0, 1024);
                if (flag)
                {
                    m_stream.Flush();
                    int num5 = m_chunkOffsets.Count % 65536 * 3 * 4;
                    m_stream.Seek(num5, SeekOrigin.Begin);
                    WriteInt(m_stream, num);
                    WriteInt(m_stream, num2);
                    WriteInt(m_stream, value);
                    m_chunkOffsets[new Point2(num, num2)] = value;
                }
            }
            catch (Exception e)
            {
                Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e));
            }
            _ = Time.RealTime;
        }
Exemplo n.º 9
0
        public unsafe void SaveChunkBlocks(TerrainChunk chunk)
        {
            _ = Time.RealTime;
            int num  = chunk.Origin.X >> 4;
            int num2 = chunk.Origin.Y >> 4;

            try
            {
                bool flag = false;
                if (m_chunkOffsets.TryGetValue(new Point2(num, num2), out long value))
                {
                    m_stream.Seek(value, SeekOrigin.Begin);
                }
                else
                {
                    flag  = true;
                    value = m_stream.Length;
                    m_stream.Seek(value, SeekOrigin.Begin);
                }
                WriteChunkHeader(m_stream, num, num2);
                try
                {
                    fixed(byte *ptr = &m_buffer[0])
                    {
                        int *ptr2 = (int *)ptr;

                        for (int i = 0; i < 16; i++)
                        {
                            for (int j = 0; j < 16; j++)
                            {
                                int num3 = TerrainChunk.CalculateCellIndex(i, 0, j);
                                int num4 = 0;
                                while (num4 < 256)
                                {
                                    *ptr2 = chunk.GetCellValueFast(num3);
                                    num4++;
                                    num3++;
                                    ptr2++;
                                }
                            }
                        }
                    }
                }
                finally
                {
                }
                m_stream.Write(m_buffer, 0, 262144);
                try
                {
                    fixed(byte *ptr = &m_buffer[0])
                    {
                        int *ptr3 = (int *)ptr;

                        for (int k = 0; k < 16; k++)
                        {
                            for (int l = 0; l < 16; l++)
                            {
                                *ptr3 = m_terrain.GetShaftValue(k + chunk.Origin.X, l + chunk.Origin.Y);
                                ptr3++;
                            }
                        }
                    }
                }
                finally
                {
                }
                m_stream.Write(m_buffer, 0, 1024);
                if (flag)
                {
                    m_stream.Flush();
                    int num5 = m_chunkOffsets.Count % 65536 * 3 * 4;
                    m_stream.Seek(num5, SeekOrigin.Begin);
                    WriteInt(m_stream, num);
                    WriteInt(m_stream, num2);
                    WriteInt(m_stream, m_chunkOffsets.Count);
                    m_chunkOffsets[new Point2(num, num2)] = value;
                }
                m_stream.Flush();
            }
            catch (Exception e)
            {
                Log.Error(ExceptionManager.MakeFullErrorMessage($"Error writing data for chunk ({num},{num2}).", e));
            }
            _ = Time.RealTime;
        }
Exemplo n.º 10
0
        public unsafe bool LoadChunkBlocks(TerrainChunk chunk)
        {
            bool result = false;
            int  num    = chunk.Origin.X >> 4;
            int  num2   = chunk.Origin.Y >> 4;

            try
            {
                if (!m_chunkOffsets.TryGetValue(new Point2(num, num2), out long value))
                {
                    return(result);
                }
                _ = Time.RealTime;
                m_stream.Seek(value, SeekOrigin.Begin);
                ReadChunkHeader(m_stream);
                m_stream.Read(m_buffer, 0, 262144);
                try
                {
                    fixed(byte *ptr = &m_buffer[0])
                    {
                        int *ptr2 = (int *)ptr;

                        for (int i = 0; i < 16; i++)
                        {
                            for (int j = 0; j < 16; j++)
                            {
                                int num3 = TerrainChunk.CalculateCellIndex(i, 0, j);
                                int num4 = 0;
                                while (num4 < 256)
                                {
                                    chunk.SetCellValueFast(num3, *ptr2);
                                    num4++;
                                    num3++;
                                    ptr2++;
                                }
                            }
                        }
                    }
                }
                finally
                {
                }
                m_stream.Read(m_buffer, 0, 1024);
                try
                {
                    fixed(byte *ptr = &m_buffer[0])
                    {
                        int *ptr3 = (int *)ptr;

                        for (int k = 0; k < 16; k++)
                        {
                            for (int l = 0; l < 16; l++)
                            {
                                m_terrain.SetShaftValue(k + chunk.Origin.X, l + chunk.Origin.Y, *ptr3);
                                ptr3++;
                            }
                        }
                    }
                }
                finally
                {
                }
                result = true;
                _      = Time.RealTime;
                return(result);
            }
            catch (Exception e)
            {
                Log.Error(ExceptionManager.MakeFullErrorMessage($"Error loading data for chunk ({num},{num2}).", e));
                return(result);
            }
        }
Exemplo n.º 11
0
        public static void Get(string address, Dictionary <string, string> parameters, Dictionary <string, string> headers, CancellableProgress progress, Action <byte[]> success, Action <Exception> failure)
        {
            MemoryStream targetStream = default(MemoryStream);
            Exception    e            = default(Exception);

            Task.Run(async delegate
            {
                _ = 3;
                try
                {
                    progress = (progress ?? new CancellableProgress());
                    if (!IsInternetConnectionAvailable())
                    {
                        throw new InvalidOperationException("Internet connection is unavailable.");
                    }
                    using (HttpClient client = new HttpClient())
                    {
                        System.Uri requestUri = (parameters != null && parameters.Count > 0) ? new System.Uri($"{address}?{UrlParametersToString(parameters)}") : new System.Uri(address);
                        client.DefaultRequestHeaders.Referrer = new System.Uri(address);
                        if (headers != null)
                        {
                            foreach (KeyValuePair <string, string> header in headers)
                            {
                                client.DefaultRequestHeaders.Add(header.Key, header.Value);
                            }
                        }
                        HttpResponseMessage responseMessage = await client.GetAsync(requestUri, HttpCompletionOption.ResponseHeadersRead, progress.CancellationToken);
                        await VerifyResponse(responseMessage);
                        long?contentLength = responseMessage.Content.Headers.ContentLength;
                        progress.Total     = contentLength.GetValueOrDefault();
                        using (Stream responseStream = await responseMessage.Content.ReadAsStreamAsync())
                        {
                            targetStream = new MemoryStream();
                            try
                            {
                                long written  = 0L;
                                byte[] buffer = new byte[1024];
                                int num;
                                do
                                {
                                    num = await responseStream.ReadAsync(buffer, 0, buffer.Length, progress.CancellationToken);
                                    if (num > 0)
                                    {
                                        targetStream.Write(buffer, 0, num);
                                        written           += num;
                                        progress.Completed = written;
                                    }
                                }while (num > 0);
                                if (success != null)
                                {
                                    Dispatcher.Dispatch(delegate
                                    {
                                        success(targetStream.ToArray());
                                    });
                                }
                            }
                            finally
                            {
                                if (targetStream != null)
                                {
                                    ((IDisposable)targetStream).Dispose();
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    e = ex;
                    Log.Error(ExceptionManager.MakeFullErrorMessage(e));
                    if (failure != null)
                    {
                        Dispatcher.Dispatch(delegate
                        {
                            failure(e);
                        });
                    }
                }
            });
        }
Exemplo n.º 12
0
 public override void Update()
 {
     try
     {
         m_stateMachine.Update();
     }
     catch (Exception e)
     {
         ScreensManager.SwitchScreen(ScreensManager.PreviousScreen);
         DialogsManager.ShowDialog(null, new MessageDialog(LanguageControl.Get(fName, 1), ExceptionManager.MakeFullErrorMessage(e), LanguageControl.Get("Usual", "ok"), null, null));
     }
 }