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.
131 lines
3.6 KiB
131 lines
3.6 KiB
using AX.DevelopEngine; |
|
using SmartX1Demo; |
|
using System; |
|
using System.Collections; |
|
using System.IO; |
|
using System.Security.Cryptography; |
|
using System.Security.Cryptography.Xml; |
|
using System.Text; |
|
using System.Xml; |
|
using UnityEngine; |
|
using AX.MessageSystem; |
|
using AX.Timer; |
|
|
|
public class SmartController : MonoSingleton<SmartController> { |
|
int[] keyHandles = new int[8]; |
|
int[] keyNumber = new int[8]; |
|
private int Rtn = 0; |
|
SmartApp smart = new SmartApp(); |
|
private Timer timer1_quit, timer2_checkExist; |
|
string appid = ""; |
|
|
|
private uint uP1 = 0x987F6BCD, uP2 = 0xE193C5B2, uP3 = 0xD507CC28, uP4 = 0x4B125AF6; |
|
|
|
public void Init() |
|
{ |
|
StartInit(); |
|
} |
|
// Use this for initialization |
|
void StartInit () { |
|
timer1_quit = new Timer(5.0f); |
|
timer1_quit.AddTimeOutEvent(() => |
|
{ |
|
//Debug.Log("程序退出!"); |
|
QuitApplicationManager.Instance.SureQuit(); |
|
}); |
|
|
|
string original_filepath = Application.dataPath + @"/xml/SmartXProject.xml"; |
|
//string encode_filepath = Application.dataPath + @"/xml/enSmartXProject.xml"; |
|
//string decode_filepath = Application.dataPath + @"/xml/deSmartXProject.xml"; |
|
|
|
XmlProcess xmlProcess = new XmlProcess(original_filepath); |
|
xmlProcess.SmartControlXML(ref appid); |
|
if (string.IsNullOrEmpty(appid)) |
|
{ |
|
QuitApplication(); |
|
return; |
|
} |
|
//检测加密狗是否存在 |
|
FindSmartX1(); |
|
|
|
timer2_checkExist = new Timer(10.0f); |
|
timer2_checkExist.AddTimeOutEvent(CheckExist); |
|
timer2_checkExist.StartTimerRepeat(); |
|
} |
|
bool FindSmartX1() |
|
{ |
|
try |
|
{ |
|
Rtn = smart.SmartX1Find(appid, keyHandles, keyNumber); |
|
if (Rtn != 0) |
|
{ |
|
Debug.Log("SmartX1Find Error,ErrorCode =" + Rtn.ToString()); |
|
QuitApplication(); |
|
return false; |
|
} |
|
Debug.Log("SmartX1Find Successfully"); |
|
return true; |
|
} |
|
catch (Exception ex) |
|
{ |
|
Debug.Log(keyHandles[0]); |
|
Debug.Log("异常" + ex.Message); |
|
QuitApplication(); |
|
return false; |
|
} |
|
} |
|
|
|
private void QuitApplication() |
|
{ |
|
timer1_quit.StartTimer(); |
|
} |
|
|
|
private void ReadStorage() |
|
{ |
|
int read_rtn = 0; |
|
byte[] pbuffer = new byte[4096]; |
|
|
|
int open_rtn = smart.SmartX1Open(keyHandles[0], (int)uP1, (int)uP2, (int)uP3, (int)uP4); |
|
if (open_rtn == 0)//打开成功 |
|
{ |
|
read_rtn = smart.SmartX1ReadStorage(keyHandles[0], 0, 4096, pbuffer); |
|
string data= Encoding.GetEncoding("gb2312").GetString(pbuffer); |
|
Debug.Log(data); |
|
} |
|
} |
|
|
|
void CheckExist() |
|
{ |
|
try |
|
{ |
|
Rtn = smart.SmartX1CheckExist(keyHandles[0]); |
|
if (Rtn != 0) |
|
{ |
|
Debug.Log("SmartX1 not exist!" + Rtn.ToString()); |
|
QuitApplication(); |
|
return; |
|
} |
|
Debug.Log("SmartX1Exist!"); |
|
return; |
|
} |
|
catch (Exception ex) |
|
{ |
|
Debug.Log(keyHandles[0]); |
|
Debug.Log("异常" + ex.Message); |
|
QuitApplication(); |
|
return; |
|
} |
|
} |
|
void OnGUI() |
|
{ |
|
if (timer1_quit.IsTimering) |
|
{ |
|
QuitApplicationManager.Instance.SetGuiTip("加密狗验证失败,程序将在 " + timer1_quit.GetRemainingTime() + " 秒后退出!"); |
|
} |
|
} |
|
// Update is called once per frame |
|
void Update () { |
|
timer1_quit.UpdateTimer(); |
|
timer2_checkExist.UpdateTimer(); |
|
} |
|
}
|
|
|