源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.1 KiB

  1. //#define USE_UPGRADEVS
  2. using UnityEngine;
  3. using System.Collections;
  4. using UnityEditor;
  5. using System.IO;
  6. using System.Text.RegularExpressions;
  7. class UpgradeVSProject : AssetPostprocessor
  8. {
  9. #if USE_UPGRADEVS
  10. private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
  11. {
  12. string currentDir = Directory.GetCurrentDirectory();
  13. string[] slnFile = Directory.GetFiles(currentDir, "*.sln");
  14. string[] csprojFile = Directory.GetFiles(currentDir, "*.csproj");
  15. bool hasChanged = false;
  16. if (slnFile != null)
  17. {
  18. for (int i = 0; i < slnFile.Length; i++)
  19. {
  20. if (ReplaceInFile(slnFile[i], "Format Version 10.00", "Format Version 11.00"))
  21. hasChanged = true;
  22. }
  23. }
  24. if (csprojFile != null)
  25. {
  26. for (int i = 0; i < csprojFile.Length; i++)
  27. {
  28. if (ReplaceInFile(csprojFile[i], "ToolsVersion=\"3.5\"", "ToolsVersion=\"4.0\""))
  29. hasChanged = true;
  30. if (ReplaceInFile(csprojFile[i], "<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>", "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>"))
  31. hasChanged = true;
  32. }
  33. }
  34. if (hasChanged)
  35. {
  36. LogManager.LogWarning("Project is now upgraded to Visual Studio 2010 Solution!");
  37. }
  38. else
  39. {
  40. LogManager.Log("Project-version has not changed...");
  41. }
  42. }
  43. static private bool ReplaceInFile(string filePath, string searchText, string replaceText)
  44. {
  45. StreamReader reader = new StreamReader(filePath);
  46. string content = reader.ReadToEnd();
  47. reader.Close();
  48. if (content.IndexOf(searchText) != -1)
  49. {
  50. content = Regex.Replace(content, searchText, replaceText);
  51. StreamWriter writer = new StreamWriter(filePath);
  52. writer.Write(content);
  53. writer.Close();
  54. return true;
  55. }
  56. return false;
  57. }
  58. #endif
  59. }