You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
3.3 KiB
136 lines
3.3 KiB
using UnityEngine; |
|
using System; |
|
using Microsoft.Win32; |
|
using System.Collections; |
|
using System.Xml; |
|
using System.IO; |
|
using System.Text; |
|
using System.Security.Cryptography; |
|
using System.Security.Cryptography.Xml; |
|
using UnityEngine.UI; |
|
using AX.DevelopEngine; |
|
using AX.Timer; |
|
public class ValidityEntiy |
|
{ |
|
private int time_days;//有效时长 |
|
public string time; |
|
private bool IsUseful; |
|
private string tip; |
|
public ValidityEntiy(string time_days) |
|
{ |
|
this.time_days = int.Parse(time_days); |
|
IsUseful = true; |
|
} |
|
public ValidityEntiy(int time_days) |
|
{ |
|
this.time_days = time_days; |
|
IsUseful = true; |
|
} |
|
public static ValidityEntiy UnValidity() |
|
{ |
|
ValidityEntiy vali = new ValidityEntiy(0); |
|
vali.tip = "试用结束,请购买正版软件!程序即将退出 "; |
|
vali.IsUseful = false; |
|
return vali; |
|
} |
|
private int DetectTime() |
|
{ |
|
if (string.IsNullOrEmpty(time)) |
|
{ |
|
return time_days; |
|
} |
|
TimeSpan span = DateTime.Now.Subtract(Convert.ToDateTime(time)); |
|
int seconds = Math.Abs(span.Seconds) + span.Minutes * 60; |
|
int days = Math.Abs(span.Days); |
|
if (days < time_days) |
|
{ |
|
return time_days - days; |
|
} |
|
else |
|
{ |
|
return -1; |
|
} |
|
|
|
} |
|
private bool CheckUseful_() |
|
{ |
|
int remainDays = DetectTime(); |
|
if (remainDays > 0) |
|
{ |
|
tip = "有效期剩余" + remainDays.ToString() + "天! "; |
|
IsUseful = true; |
|
} |
|
else |
|
{ |
|
tip = "试用结束,请购买正版软件!程序即将退出 "; |
|
IsUseful = false; |
|
} |
|
return IsUseful; |
|
} |
|
public string GetTip() |
|
{ |
|
return tip; |
|
} |
|
public bool CheckUseful() |
|
{ |
|
if (!IsUseful) |
|
return IsUseful; |
|
|
|
return CheckUseful_(); |
|
} |
|
public bool GetUseful() |
|
{ |
|
return IsUseful; |
|
} |
|
} |
|
public class LinqToXMLAndEncrypt |
|
{ |
|
//设置密钥,根据平台而定 |
|
static string dataKey = SystemInfo.deviceUniqueIdentifier; |
|
static string xmlpath = Application.dataPath + @"/xml/"; |
|
} |
|
public class ValidityDetection : MonoSingleton<ValidityDetection> { |
|
|
|
XmlProcess xmlProcess; |
|
private RegistryKey rsgTime = null; |
|
private Timer timer_quit; |
|
ValidityEntiy vali; |
|
public void Init() { } |
|
// Use this for initialization |
|
void Start() |
|
{ |
|
var original_filepath = Application.dataPath + @"/xml/" + "validity.xml"; |
|
//执行该函数即检测有效性 |
|
xmlProcess = new XmlProcess(original_filepath); |
|
vali = xmlProcess.GetValidityEntiy("assets"); |
|
vali.CheckUseful(); |
|
timer_quit = new Timer(5.0f); |
|
timer_quit.AddTimeOutEvent(() => |
|
{ |
|
if (vali.GetUseful()) |
|
{ |
|
QuitApplicationManager.Instance.SetGuiTip("", false); |
|
} |
|
else |
|
{ |
|
QuitApplicationManager.Instance.SureQuit(); |
|
} |
|
}); |
|
timer_quit.StartTimer(); |
|
} |
|
|
|
void OnGUI() |
|
{ |
|
if (timer_quit.IsTimering) |
|
{ |
|
QuitApplicationManager.Instance.SetGuiTip(vali.GetTip() + timer_quit.GetRemainingTime()); |
|
} |
|
|
|
} |
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
timer_quit.UpdateTimer(); |
|
} |
|
|
|
}
|
|
|