private void SaveCredentialsToFile(GitCredentialsJson credentials) { if (ValidateCredentialsPath()) { string credentialsFilePath = paths.CredentialsFilePath; try { string json = JsonUtility.ToJson(credentials); using (var fileStream = new FileStream(credentialsFilePath, FileMode.OpenOrCreate, FileAccess.Write)) using (DESCryptoServiceProvider p = new DESCryptoServiceProvider()) using (var dec = p.CreateEncryptor(Encoding.ASCII.GetBytes(KeyOne), Encoding.ASCII.GetBytes(KeyTwo))) using (CryptoStream cryptoStream = new CryptoStream(fileStream, dec, CryptoStreamMode.Write)) using (StreamWriter streamWriter = new StreamWriter(cryptoStream)) { streamWriter.Write(json); } } catch (Exception e) { logger.LogFormat(LogType.Error, "Could not serialize GitCredentialsJson to json file at: {0}", credentialsFilePath); logger.LogException(e); } } }
private static void LoadGitCredentials() { string credentialsFilePath = CredentialsFilePath; GitCredentialsJson credentialsJson = null; if (File.Exists(credentialsFilePath)) { try { credentialsJson = JsonUtility.FromJson <GitCredentialsJson>(File.ReadAllText(credentialsFilePath)); } catch (Exception e) { Debug.LogError("Could not deserialize git settings. Creating new settings."); Debug.LogException(e); } } if (credentialsJson == null) { credentialsJson = new GitCredentialsJson(); var oldCredentialsFile = EditorGUIUtility.Load("UniGit/Git-Credentials.asset") as GitCredentials; if (oldCredentialsFile != null) { //must be delayed call for unity to deserialize credentials file properly EditorApplication.delayCall += ImportFromOldCredentials; } else { SaveCredentialsToFile(credentialsJson); } } gitCredentials = credentialsJson; }
private void LoadGitCredentials() { string credentialsFilePath = paths.CredentialsFilePath; GitCredentialsJson credentialsJson = null; if (File.Exists(credentialsFilePath)) { try { try { using (var fileStream = new FileStream(credentialsFilePath, FileMode.Open, FileAccess.Read)) using (DESCryptoServiceProvider p = new DESCryptoServiceProvider()) using (var dec = p.CreateDecryptor(Encoding.ASCII.GetBytes(KeyOne), Encoding.ASCII.GetBytes(KeyTwo))) using (CryptoStream cryptoStream = new CryptoStream(fileStream, dec, CryptoStreamMode.Read)) using (StreamReader streamReader = new StreamReader(cryptoStream)) { string text = streamReader.ReadToEnd(); credentialsJson = JsonUtility.FromJson <GitCredentialsJson>(text); } } catch { using (var fileStream = new FileStream(credentialsFilePath, FileMode.Open, FileAccess.Read)) using (StreamReader streamReader = new StreamReader(fileStream)) { credentialsJson = JsonUtility.FromJson <GitCredentialsJson>(streamReader.ReadToEnd()); } } } catch (Exception e) { logger.Log(LogType.Error, "Could not deserialize git settings. Creating new settings."); logger.LogException(e); } } if (credentialsJson == null) { credentialsJson = new GitCredentialsJson(); var oldCredentialsFile = EditorGUIUtility.Load("UniGit/Git-Credentials.asset") as GitCredentials; if (oldCredentialsFile != null) { //must be delayed call for unity to deserialize credentials file properly EditorApplication.delayCall += ImportFromOldCredentials; } else { SaveCredentialsToFile(credentialsJson); } } gitCredentials = credentialsJson; }
private static void SaveCredentialsToFile(GitCredentialsJson credentials) { ValidateCredentialsPath(); string credentialsFilePath = CredentialsFilePath; try { string json = JsonUtility.ToJson(credentials); File.WriteAllText(credentialsFilePath, json); } catch (Exception e) { Debug.LogError("Could not serialize GitCredentialsJson to json file at: " + credentialsFilePath); Debug.LogException(e); } }