Beispiel #1
0
        private static void CommandThreadStartWin(string path)
        {
            Process process = new Process();

            process.StartInfo.FileName               = path;
            process.StartInfo.CreateNoWindow         = false;
            process.StartInfo.ErrorDialog            = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;

            process.Start();
            string outPutstr = process.StandardOutput.ReadToEnd();

            if (!string.IsNullOrEmpty(outPutstr))
            {
                Log.I(outPutstr);
            }

            process.WaitForExit();
            process.Close();

            string        content;
            DirectoryInfo root = new DirectoryInfo(UnityEngine.Application.streamingAssetsPath + "/config");

            FileInfo[] files = root.GetFiles();
            foreach (var item in files)
            {
                if (item.FullName.Contains("meta"))
                {
                    continue;
                }

                using (StreamReader sr = item.OpenText())
                {
                    content = sr.ReadToEnd();
                    content = EncryptUtil.AesStr(content, SaveSetting.m_AESKeyValue, SaveSetting.m_AESIvValue);
                    sr.Close();
                }
                using (FileStream fs = item.OpenWrite())
                {
                    fs.SetLength(0);
                    byte[] writeDataArray = System.Text.UTF8Encoding.UTF8.GetBytes(content);
                    fs.Write(writeDataArray, 0, writeDataArray.Length);
                    fs.Flush();
                }
            }
        }
Beispiel #2
0
        public static bool SerializeJson(string path, object obj, bool encry)
        {
            if (string.IsNullOrEmpty(path))
            {
                Log.I("SerializeJson Without Valid Path.");
                return(false);
            }

            if (obj == null)
            {
                Log.I("SerializeJson obj is Null.");
                return(false);
            }

            string jsonValue = null;

            try
            {
                jsonValue = JsonMapper.ToJson(obj);
                if (encry)
                {
                    jsonValue = EncryptUtil.AesStr(jsonValue, "weoizkxjkfs", "asjkdyweucn");
                }
            }
            catch (Exception e)
            {
                Log.I(e);
                return(false);
            }

            FileInfo fileInfo = new FileInfo(path);

            if (fileInfo.Exists)
            {
                fileInfo.Delete();
            }

            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                byte[] writeDataArray = UTF8Encoding.UTF8.GetBytes(jsonValue);
                fs.Write(writeDataArray, 0, writeDataArray.Length);
                fs.Flush();
            }

            return(true);
        }
Beispiel #3
0
        private void btnStartAuth_Click(object sender, EventArgs e)
        {
            string[]      arr  = txtGroupInfo.Text.Split('\n');
            List <string> list = new List <string>();

            foreach (var str in arr)
            {
                if (!string.IsNullOrEmpty(str.Trim()))
                {
                    list.Add(str.Replace("\r", ""));
                }
            }
            if (list.Count == 0)
            {
                MessageBox.Show("请填写发包方编码!");
                return;
            }
            //确认填写信息
            if (
                MessageBox.Show(@"本次将授权" + list.Count + "组发包方信息", "确认生成信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var str in list)
                {
                    sb.AppendLine(EncryptUtil.AesStr(str, keyVal, ivVal));
                }
                string filePath = Path.Combine(txtCombinePath.Text.Trim(), "Spire.Excel.dll");
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                File.WriteAllText(filePath, sb.ToString());
                MessageBox.Show("授权成功!");
            }
        }
Beispiel #4
0
        public void Write(T t, SaveSetting saveSetting)
        {
            string jsonValue = null;

            try
            {
                jsonValue = JsonConvert.SerializeObject(t);
                switch (saveSetting.EncryptType)
                {
                case EncryptType.None:
                    break;

                case EncryptType.AES:
                    jsonValue = EncryptUtil.AesStr(jsonValue, SaveSetting.m_AESKeyValue, SaveSetting.m_AESIvValue);
                    break;
                }
            }
            catch (Exception e)
            {
                Log.I(string.Format("{0}{1}:{2}", t.GetType().Name, "写入失败", e));
                return;
            }

            FileInfo fileInfo;

            fileInfo = new FileInfo(string.Format("{0}/{1}.json", saveSetting.DataPath, saveSetting.DataName));

            if (!Directory.Exists(saveSetting.DataPath))
            {
                Directory.CreateDirectory(saveSetting.DataPath);
            }
            if (!fileInfo.Exists)
            {
                fileInfo.Create().Dispose();
            }
            using (FileStream fs = fileInfo.OpenWrite())
            {
                fs.SetLength(0);
                byte[] writeDataArray = UTF8Encoding.UTF8.GetBytes(jsonValue);
                fs.Write(writeDataArray, 0, writeDataArray.Length);
                fs.Flush();
                Log.I(string.Format("{0}:{1}", t.GetType().Name, "Write Success"));
            }

#if UNITY_EDITOR
            #region //保险起见,persistentDataPath路径也做存储
            FileInfo fileInfo1;
            fileInfo1 = new FileInfo(string.Format("{0}/{1}.json", Application.persistentDataPath, saveSetting.DataName));

            if (!fileInfo1.Exists)
            {
                fileInfo1.Delete();
            }
            else
            {
                fileInfo1.Create().Dispose();
            }
            using (FileStream fs = fileInfo1.OpenWrite())
            {
                byte[] writeDataArray = UTF8Encoding.UTF8.GetBytes(jsonValue);
                fs.Write(writeDataArray, 0, writeDataArray.Length);
                fs.Flush();
            }
            #endregion
#endif
        }