Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. // This file is provided under The MIT License as part of Steamworks.NET.
  2. // Copyright (c) 2013-2018 Riley Labrecque
  3. // Please see the included LICENSE.txt for additional information.
  4.  
  5. #if UNITY_ANDROID || UNITY_IOS || UNITY_TIZEN || UNITY_TVOS || UNITY_WEBGL || UNITY_WSA || UNITY_PS4 || UNITY_WII || UNITY_XBOXONE || UNITY_SWITCH
  6. #define DISABLESTEAMWORKS
  7. #endif
  8.  
  9. #if !DISABLESTEAMWORKS
  10.  
  11. // Add 'DISABLEREDISTCOPY' to your custom platform defines to disable automatic copying!
  12. #if UNITY_5_3_OR_NEWER
  13. #define DISABLEREDISTCOPY
  14. #endif
  15.  
  16. using UnityEngine;
  17. using UnityEditor;
  18. using UnityEditor.Callbacks;
  19. using Steamworks;
  20. using System.IO;
  21.  
  22. public class RedistCopy {
  23. [PostProcessBuild]
  24. public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
  25. string baseDir;
  26. string pluginsDir;
  27. switch(target)
  28. {
  29. case BuildTarget.StandaloneWindows:
  30. case BuildTarget.StandaloneWindows64:
  31. baseDir = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data");
  32. pluginsDir = Path.Combine(baseDir, "Plugins");
  33. break;
  34. case BuildTarget.StandaloneLinux:
  35. baseDir = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data");
  36. pluginsDir = Path.Combine(Path.Combine(baseDir, "Plugins"), "x86");
  37. break;
  38. case BuildTarget.StandaloneLinux64:
  39. case BuildTarget.StandaloneLinuxUniversal:
  40. baseDir = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), Path.GetFileNameWithoutExtension(pathToBuiltProject) + "_Data");
  41. pluginsDir = Path.Combine(Path.Combine(baseDir, "Plugins"), "x86_64");
  42. break;
  43. #if UNITY_2017_3_OR_NEWER
  44. case BuildTarget.StandaloneOSX:
  45. #else
  46. case BuildTarget.StandaloneOSXIntel:
  47. case BuildTarget.StandaloneOSXIntel64:
  48. case BuildTarget.StandaloneOSXUniversal:
  49. #endif
  50. baseDir = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), Path.GetFileNameWithoutExtension(pathToBuiltProject) + ".app");
  51. baseDir = Path.Combine(baseDir, "Contents");
  52. pluginsDir = Path.Combine(baseDir, "Plugins");
  53. break;
  54. default:
  55. return;
  56. }
  57.  
  58. string[] DebugInfo = {
  59. "Steamworks.NET created by Riley Labrecque",
  60. "http://steamworks.github.io",
  61. "",
  62. "Steamworks.NET Version: " + Steamworks.Version.SteamworksNETVersion,
  63. "Steamworks SDK Version: " + Steamworks.Version.SteamworksSDKVersion,
  64. "Steam API DLL Version: " + Steamworks.Version.SteamAPIDLLVersion,
  65. "Steam API DLL Size: " + Steamworks.Version.SteamAPIDLLSize,
  66. "Steam API64 DLL Size: " + Steamworks.Version.SteamAPI64DLLSize,
  67. ""
  68. };
  69. File.WriteAllLines(Path.Combine(pluginsDir, "Steamworks.NET.txt"), DebugInfo);
  70.  
  71. #if !DISABLEREDISTCOPY
  72. if (target == BuildTarget.StandaloneWindows64) {
  73. CopyFile("steam_api64.dll", "steam_api64.dll", "Assets/Plugins/x86_64", pathToBuiltProject);
  74. }
  75. else if (target == BuildTarget.StandaloneWindows) {
  76. CopyFile("steam_api.dll", "steam_api.dll", "Assets/Plugins/x86", pathToBuiltProject);
  77. }
  78.  
  79. string controllerCfg = Path.Combine(Application.dataPath, "controller.vdf");
  80. if (File.Exists(controllerCfg)) {
  81. string strFileDest = Path.Combine(baseDir, "controller.vdf");
  82.  
  83. File.Copy(controllerCfg, strFileDest);
  84. File.SetAttributes(strFileDest, File.GetAttributes(strFileDest) & ~FileAttributes.ReadOnly);
  85.  
  86. if (!File.Exists(strFileDest)) {
  87. Debug.LogWarning("[Steamworks.NET] Could not copy controller.vdf into the built project. File.Copy() Failed. Place controller.vdf from the Steamworks SDK in the output dir manually.");
  88. }
  89. }
  90. #endif
  91. }
  92.  
  93. static void CopyFile(string filename, string outputfilename, string pathToFile, string pathToBuiltProject) {
  94. string strCWD = Directory.GetCurrentDirectory();
  95. string strSource = Path.Combine(Path.Combine(strCWD, pathToFile), filename);
  96. string strFileDest = Path.Combine(Path.GetDirectoryName(pathToBuiltProject), outputfilename);
  97.  
  98. if (!File.Exists(strSource)) {
  99. Debug.LogWarning(string.Format("[Steamworks.NET] Could not copy {0} into the project root. {0} could not be found in '{1}'. Place {0} from the redist into the project root manually.", filename, pathToFile));
  100. return;
  101. }
  102.  
  103. if (File.Exists(strFileDest)) {
  104. if (File.GetLastWriteTime(strSource) == File.GetLastWriteTime(strFileDest)) {
  105. FileInfo fInfo = new FileInfo(strSource);
  106. FileInfo fInfo2 = new FileInfo(strFileDest);
  107. if (fInfo.Length == fInfo2.Length) {
  108. return;
  109. }
  110. }
  111. }
  112.  
  113. File.Copy(strSource, strFileDest, true);
  114. File.SetAttributes(strFileDest, File.GetAttributes(strFileDest) & ~FileAttributes.ReadOnly);
  115.  
  116. if (!File.Exists(strFileDest)) {
  117. Debug.LogWarning(string.Format("[Steamworks.NET] Could not copy {0} into the built project. File.Copy() Failed. Place {0} from the redist folder into the output dir manually.", filename));
  118. }
  119. }
  120. }
  121.  
  122. #endif // !DISABLESTEAMWORKS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement