Ejemplo n.º 1
0
    static void SaveToFile(string fileName, bool encrypt)
    {
        if (fileName.Contains(ENCRYPTION_SYMBOL))
        {
            fileName = fileName.Replace(ENCRYPTION_SYMBOL, "");
        }
        string fullName       = fileName + filesExtension;
        string fullCryptoName = fileName + ENCRYPTION_SYMBOL + filesExtension;
        string filePath       = Data.FilesPath + fullName;
        string cryptoFilePath = Data.FilesPath + fullCryptoName;

        string json = JsonUtility.ToJson(Data);

        if (encrypt)
        {
            if (File.Exists(filePath)) // Delete old file
            {
                File.Delete(filePath);
                //Debug.Log("delete old " + fullName);
            }
            byte[] encryptedData = crypto.Encrypt(json, ENCRYPTION_KEY);
            File.WriteAllBytes(cryptoFilePath, encryptedData);
            //Debug.Log("save encrypted " + fullCryptoName);
            onSaveFinish?.Invoke();
        }
        else
        {
            if (File.Exists(cryptoFilePath)) // Delete old encrypted file
            {
                File.Delete(cryptoFilePath);
                //Debug.Log("delete crypto " + fullCryptoName);
            }
            File.WriteAllText(filePath, json);
            //Debug.Log("save " + fullName);
            onSaveFinish?.Invoke();
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 保存DNS记录回调
 /// </summary>
 /// <param name="result"></param>
 private void EditFinishCallBack(DnsOperatorResult result)
 {
     //错误则显示错误信息
     if (result.code != 0)
     {
         mMainWindow.SetStatustProgess(new MainWindowStatusNotify()
         {
             alertLevel = AlertLevel.ERROR,
             message    = string.Format("[{0}]{1}", result.code, result.message)
         });;
         //win.SetStatusBarText(AlertLevel.ERROR, result.message);
     }
     else
     {
         LoadDnsRecord();
     }
     //触发完成事件
     OnSaveFinish?.Invoke(result);
 }