174 lines
5.5 KiB
C#
174 lines
5.5 KiB
C#
using LitJson;
|
||
using System;
|
||
using System.IO;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ReadLoginInfo : MonoBehaviour
|
||
{
|
||
public Text Text_Error;
|
||
public Menu menu;
|
||
void Start()
|
||
{
|
||
//Invoke("Load", 1);
|
||
LoadInfo();
|
||
}
|
||
void Load()
|
||
{
|
||
string tempStr;
|
||
int i;
|
||
string path = System.Environment.CurrentDirectory + "/User.config";
|
||
Debug.Log(path);
|
||
//Text_Error.text = path;
|
||
if (File.Exists(path))
|
||
{
|
||
StreamReader file = new StreamReader(path, Encoding.UTF8);
|
||
tempStr = file.ReadLine().Trim();
|
||
while (tempStr != null)
|
||
{
|
||
if (tempStr.Contains(":"))
|
||
{
|
||
i = tempStr.IndexOf(":");
|
||
if (i < tempStr.Length - 1)
|
||
{
|
||
PlayerPrefs.SetString(tempStr.Substring(0, i), tempStr.Substring(i + 1));
|
||
//Debug.Log("添加:" + tempStr.Substring(0, i) + "内容" + tempStr.Substring(i + 1));
|
||
}
|
||
}
|
||
tempStr = null;
|
||
tempStr = file.ReadLine();
|
||
}
|
||
//删除文件
|
||
file.Close();
|
||
//File.Delete(path);
|
||
//读取完成
|
||
DateTime dt = DateTime.Parse(PlayerPrefs.GetString("登录时间").Trim());
|
||
TimeSpan ts = DateTime.Now - dt;
|
||
//Debug.Log(DateTime.Now);
|
||
if (ts.Minutes > 5)//超时
|
||
{
|
||
//Text_Error.text = "超时";
|
||
Debug.Log("超时");
|
||
Debug.Log(PlayerPrefs.GetString("登录时间"));
|
||
//Application.Quit();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Text_Error.text = "文件不存在";
|
||
Debug.Log("文件不存在");
|
||
//Application.Quit();
|
||
}
|
||
}
|
||
void LoadInfo()
|
||
{
|
||
string tempStr;
|
||
string path = Application.streamingAssetsPath + "/info.ini";
|
||
Debug.Log(path);
|
||
if (File.Exists(path))
|
||
{
|
||
|
||
tempStr = File.ReadAllText(path); Debug.Log(tempStr);
|
||
string[] data = tempStr.Split(new char[] { '#' });
|
||
DateTime dt = DateTime.Parse(data[0]);
|
||
TimeSpan ts = DateTime.Now - dt;
|
||
Debug.Log(dt);
|
||
Debug.Log(DateTime.Now);
|
||
Debug.Log(ts.Seconds);
|
||
if (ts.Seconds > 60)
|
||
{
|
||
Text_Error.text = "超时";
|
||
Debug.Log("超时");
|
||
Debug.Log(data[0]);
|
||
}
|
||
else
|
||
{
|
||
|
||
|
||
//string tmps = "采购物资入库";
|
||
|
||
//Debug.Log((GBToUnicode(tmps)));
|
||
|
||
if (data[1].Equals("local"))
|
||
{
|
||
menu.NoDataPanel.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
; string[] a = data[1].Split(new char[] { ';' });
|
||
|
||
|
||
string[] taskData = data[1].Split(new char[] { ';' });
|
||
if (taskData[1].Equals("0"))
|
||
{
|
||
string v = UnicodeToGB(taskData[2].Replace("%5C", "\\"));
|
||
PlayerPrefs.SetString("task_type", "学习");
|
||
if (v.Contains("调拨"))
|
||
{
|
||
PlayerPrefs.SetString("Practices", "调拨");
|
||
}
|
||
else
|
||
{
|
||
|
||
Debug.Log(v);
|
||
PlayerPrefs.SetString("Practices", v);
|
||
}
|
||
menu.stuBtn.onClick.Invoke();
|
||
}
|
||
else
|
||
{
|
||
PlayerPrefs.SetString("task_type", "考试");
|
||
PlayerPrefs.SetString("id", taskData[2]);
|
||
menu.examBtn.onClick.Invoke();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public string UnicodeToGB(string text)
|
||
{
|
||
MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
|
||
if (mc != null && mc.Count > 0)
|
||
{
|
||
StringBuilder sb = new StringBuilder();
|
||
foreach (Match m2 in mc)
|
||
{
|
||
string v = m2.Value;
|
||
string word = v.Substring(2);
|
||
byte[] codes = new byte[2];
|
||
int code = Convert.ToInt32(word.Substring(0, 2), 16);
|
||
int code2 = Convert.ToInt32(word.Substring(2), 16);
|
||
codes[0] = (byte)code2;
|
||
codes[1] = (byte)code;
|
||
sb.Append(Encoding.Unicode.GetString(codes));
|
||
}
|
||
return sb.ToString();
|
||
}
|
||
else
|
||
{
|
||
return text;
|
||
}
|
||
}
|
||
public static string GBToUnicode(string text)
|
||
{
|
||
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(text);
|
||
string lowCode = "", temp = "";
|
||
for (int i = 0; i < bytes.Length; i++)
|
||
{
|
||
if (i % 2 == 0)
|
||
{
|
||
temp = System.Convert.ToString(bytes[i], 16);//取出元素4编码内容(两位16进制)
|
||
if (temp.Length < 2) temp = "0" + temp;
|
||
}
|
||
else
|
||
{
|
||
string mytemp = Convert.ToString(bytes[i], 16);
|
||
if (mytemp.Length < 2) mytemp = "0" + mytemp; lowCode = lowCode + @"\u" + mytemp + temp;//取出元素4编码内容(两位16进制)
|
||
}
|
||
}
|
||
return lowCode;
|
||
}
|
||
}
|