XCPlist.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. namespace cn.sharesdk.unity3d.sdkporter
  6. {
  7. public partial class XCPlist : System.IDisposable
  8. {
  9. private string filePath;
  10. List<string> contents = new List<string>();
  11. public XCPlist(string fPath)
  12. {
  13. filePath = Path.Combine( fPath, "info.plist" );
  14. if( !System.IO.File.Exists( filePath ) ) {
  15. Debug.LogError( filePath +"路径下文件不存在" );
  16. return;
  17. }
  18. FileInfo projectFileInfo = new FileInfo( filePath );
  19. StreamReader sr = projectFileInfo.OpenText();
  20. while (sr.Peek() >= 0)
  21. {
  22. contents.Add(sr.ReadLine());
  23. }
  24. sr.Close();
  25. }
  26. public void AddKey(string key)
  27. {
  28. if(contents.Count < 2)
  29. return;
  30. contents.Insert(contents.Count - 2,key);
  31. }
  32. public void ReplaceKey(string key,string replace){
  33. for(int i = 0;i < contents.Count;i++){
  34. if(contents[i].IndexOf(key) != -1){
  35. contents[i] = contents[i].Replace(key,replace);
  36. }
  37. }
  38. }
  39. public void Save()
  40. {
  41. StreamWriter saveFile = File.CreateText(filePath);
  42. foreach(string line in contents)
  43. saveFile.WriteLine(line);
  44. saveFile.Close();
  45. }
  46. public void Dispose()
  47. {
  48. }
  49. }
  50. }