コード例 #1
0
ファイル: HQ.cs プロジェクト: Hengle/clapotis
        /// <summary>
        /// For the curious who might want to know why I send these stats.
        /// I need some info about Unity Editor usage, especially because Unity does not provide them.
        /// In order to keep supporting old versions or platforms.
        /// </summary>
        /// <param name="sendStats"></param>
        internal static void    SendStats(bool sendStats = true)
        {
            string path     = Path.Combine(Application.persistentDataPath, Path.Combine(Constants.InternalPackageTitle, "sendStats." + Utility.UnityVersion + "." + Constants.Version + ".txt"));
            bool   sentOnce = false;
            string today    = DateTime.Now.ToString("yyyyMMdd");

            if (File.Exists(path) == true)
            {
                string lastTime = File.ReadAllText(path);

                if (lastTime == today)
                {
                    sentOnce = true;
                }
            }

            if (sentOnce == false)
            {
                try
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(path));
                    File.WriteAllText(path, today);
                }
                catch
                {
                    string rawSentOnceCount = HQ.GetStatsComplementary("SSSOC");
                    int    errorCount;

                    if (string.IsNullOrEmpty(rawSentOnceCount) == false && int.TryParse(rawSentOnceCount, out errorCount) == true)
                    {
                        HQ.SetStatsComplementary("SSSOC", (errorCount + 1).ToString());
                    }
                    else
                    {
                        HQ.SetStatsComplementary("SSSOC", "1");
                    }
                }
            }

            if (sentOnce == false || sendStats == false)
            {
                StringBuilder buffer = Utility.GetBuffer(HQ.ServerEndPoint + "unityeditor.php?u=");

                buffer.Append(Utility.UnityVersion);
                buffer.Append("&o=");
                buffer.Append(SystemInfo.operatingSystem);
                buffer.Append("&p=");
                buffer.Append(Constants.Version);
                buffer.Append("&n=");
                buffer.Append(SystemInfo.deviceName);
                buffer.Append("&un=");
                buffer.Append(Environment.UserName);
                buffer.Append("&ut=");
                buffer.Append(Metrics.GetUsedTools());
                Metrics.ResetUsedTools();

                buffer.Append("&m=");
                buffer.Append(HQ.GetMACAddressHash());

                foreach (License license in NGLicensesManager.EachInvoices())
                {
                    if (license.active == true && license.status != Status.Banned)
                    {
                        buffer.Append("&in[]=");
                        buffer.Append(license.invoice);
                    }
                }

                foreach (HQ.ToolAssemblyInfo tool in HQ.EachTool)
                {
                    buffer.Append("&to[]=");
                    buffer.Append(tool.name);
                    buffer.Append(":");
                    buffer.Append(tool.version);
                }

                string complementary = NGEditorPrefs.GetString(HQ.ComplementaryKeyPref);
                if (string.IsNullOrEmpty(complementary) == false)
                {
                    buffer.Append("&com=" + complementary);
                }

                if (sendStats == false)
                {
                    buffer.Append("&s");
                }

                Utility.RequestURL(Utility.ReturnBuffer(buffer), (s, r) =>
                {
                    if (s == Utility.RequestStatus.Completed)
                    {
                        NGEditorPrefs.DeleteKey(HQ.ComplementaryKeyPref);
                    }
                    else
                    {
                        string rawErrorCount = HQ.GetStatsComplementary("SSEC");
                        int errorCount;

                        if (string.IsNullOrEmpty(rawErrorCount) == false && int.TryParse(rawErrorCount, out errorCount) == true)
                        {
                            HQ.SetStatsComplementary("SSEC", (errorCount + 1).ToString());
                        }
                        else
                        {
                            HQ.SetStatsComplementary("SSEC", "1");
                        }
                    }
                });
            }
        }