using UnityEditor; using UnityEngine; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Reflection; using Perforce.P4; namespace P4Connect { [InitializeOnLoad] public static class KickMe { private static bool _ranOnce; static KickMe() { EditorApplication.update += RunOnceCallback; } static void RunOnceCallback() { if (EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode) return; //Debug.Log("RunOnceCallback()"); if (!_ranOnce) { _ranOnce = true; EditorApplication.update -= RunOnceCallback; Debug.Log("P4Connect: " + Version.PerforceReleaseString + "-" + Version.Build + " unityVersion: " + Application.unityVersion); Main.Initialize(); Icons.UpdateDisplay(); return; } } } public static class Main { // Path to the Asset folder public static string DataPath { get; private set; } // Path the project folder public static string RootPath { get; private set; } // The name of the current project public static string ProjectName { get; private set; } // Import this method to override the DLLImport search directory, so that P4API.NET can load P4Bridge [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool SetDllDirectory(string lpPathName); // Import this method to retrieve the DLLImport search directory [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern int GetDllDirectory(int nBufferLength, StringBuilder lpPathName); // Import this method to retrieve the DLLImport search directory [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern IntPtr LoadLibrary(string lpModuleName); [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] static extern bool FreeLibrary(IntPtr href); /// <summary> /// Static constructor /// </summary> static Main() { Initialize(); } /// <summary> /// Initialize the different parts of P4Connect /// </summary> public static void Initialize() { DateTime startTimestamp = DateTime.Now; SetupRootDirectory(); SetDLLDirectory(); Config.Initialize(); ChangeManager.Initialize(); Engine.Initialize(); AssetBridge.Initialize(); UnityVSBridge.Initialize(); AssetStatusCache.Initialize(); Icons.Initialize(); // First time - always check out sln files if (Config.IncludeSolutionFiles) { AssetBridge.CheckoutProjectFiles(false, true); } PendingChanges.UpdateDisplay(); if (Config.DisplayP4Timings) { double deltaTime = (DateTime.Now - startTimestamp).TotalMilliseconds; StringBuilder builder = new StringBuilder(); UnityEngine.Debug.Log("P4Connect - Initialization Time: " + deltaTime + " ms"); } //Debug.Log("P4Connect Main Initialize Complete "); } /// <summary> /// Initializes the root directory, asset directory and project name /// </summary> static void SetupRootDirectory() { // Grab all the directories and project names from the asset folder DataPath = Application.dataPath; string[] path = DataPath.Split(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar); RootPath = ""; for (int i = 0; i < path.Length - 1; ++i) RootPath += path[i] + System.IO.Path.DirectorySeparatorChar; ProjectName = path[path.Length - 2]; } // Return the currently stored DLL Directory public static string GetDLLDirectory() { StringBuilder tmp = new StringBuilder(10240); if (GetDllDirectory(10240, tmp) == 0) { int err = Marshal.GetLastWin32Error(); UnityEngine.Debug.LogError("GetDllDirectory returned error:" + err.ToString()); return null; } return tmp.ToString(); } public static IntPtr href = IntPtr.Zero; /// <summary> /// Allow users to override the dll search directory /// </summary> public static void SetDLLDirectory() { if (Application.platform == RuntimePlatform.WindowsEditor) { if (Utils.IsRunningUnity5()) // Unity 5.X on Windows { // Do nothing. Unity5 will mess up any SetDLLDirectory we try to do. } else // Unity 4.X on Windows { // Force the DLL search directory as soon as possible string path = Utils.GetBridgeDirectory(); // Debug.Log("SetDLLDirectory to " + path); SetDllDirectory(path); href = LoadLibrary("p4bridge"); // This global handle is never freed if (href == IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); UnityEngine.Debug.Log("p4bridge LoadLibrary Error: " + err.ToString()); } else { UnityEngine.Debug.Log("LoadLibrary Success!"); } } } else if (Application.platform == RuntimePlatform.OSXEditor) { bool copyit = false; string dylibSourcePath = System.IO.Path.Combine(Utils.GetBridgeDirectory(), Config.P4BridgeDylibName); string dylibDestPath = System.IO.Path.Combine(RootPath, Config.P4BridgeDylibName); //Debug.Log("src: " + dylibSourcePath); //Debug.Log("dst: " + dylibDestPath); if (System.IO.File.Exists(dylibDestPath)) // Compare the filesizes if both files exist. { System.IO.FileInfo fisrc = new System.IO.FileInfo(dylibSourcePath); System.IO.FileInfo fidst = new System.IO.FileInfo(dylibDestPath); if (fisrc.Length != fidst.Length) { copyit = true; } } else { copyit = true; } if (copyit) { System.IO.File.Copy(dylibSourcePath, dylibDestPath, true); EditorUtility.DisplayDialog("Restart Unity?", "In order for P4Connect to function on OSX, P4Connect\n" + "had to copy libP4Bridge.dylib to the root folder of your project\n" + "You now have to restart Unity for it to properly load the dylib.", "Ok"); } } else { Debug.Log("Invalid application platform " + Application.platform); Debug.Log("Please change project settings to 'PC Mac Linux - Standalone' to enable P4Connect"); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 21095 | artofcode |
Populate -o //guest/perforce_software/p4connect/... //guest/artofcode/dev/p4connect/.... |
||
//guest/perforce_software/p4connect/main/src/P4Connect/P4Connect/P4Connect.Main.cs | |||||
#6 | 20275 | Norman Morse |
Update source to match 2016.2 patch 2 release Much thrashing of source during refactor. Proper caching of asset statuses, reducing fstats issued. Some bug fixes by Liz Lam Cleanup of Pending changes, rework of initialization and play/stop play transitions |
||
#5 | 19279 | Norman Morse |
Update workshop from internal changes. These Changes are the basis of the 2016.2 release - Dropped support for Unity 4 - Built in Unity 5 - Fixed assembly misidentifications. - Fixed problem where configuration dialog would pop up between runs |
||
#4 | 18942 | Norman Morse | 2016.1 Patch 2 changes | ||
#3 | 18665 | Norman Morse | 16.2 preparation checkin | ||
#2 | 18418 | Norman Morse |
Many changes from the dev branch. Icons are packaged differently. Style Sheet is created / used New ConnectionWizard Dialog New PasswordDialog Generate -a tickets Update version to 2016.1.0.0 |
||
#1 | 16209 | Norman Morse | Move entire source tree into "main" branch so workshop code will act correctly. | ||
//guest/perforce_software/p4connect/src/P4Connect/P4Connect/P4Connect.Main.cs | |||||
#15 | 16117 | Norman Morse |
Fix for EditorPrefs related Disconnection. Cleaned up some code. Removed Spurious Comments Initialize Config from within Main |
||
#14 | 15298 | Norman Morse | Fix Version Stamping to not use UpdateVersion.exe for personal (workshop) builds. | ||
#13 | 15266 | Norman Morse |
Integrated "UpdateVersion" tool to update the VersionInfo and the DLL properties with information from "Version" EC generates the Version file for us in builds. Workshop users need to generate their own Release number with two zeros (like 2015.2.0.0) which will have the last two numbers replaced with change ID. |
||
#12 | 15245 | Norman Morse |
Missed a couple files. Bumped version to 2.8 2015.2 |
||
#11 | 14801 | Norman Morse |
GA.9 changes. Fixed debug message exceptions Improved Pending Changes dialog for large changesets Changed configuration to allow saving configuration with Perforce disabled. Improved restart after recompile, automatically attempts connection now unless disabled. |
||
#10 | 13864 | Norman Morse | Final fixes for GA.5 release. | ||
#9 | 12862 | Norman Morse |
Fixed problem with an empty default change list not refresshing. Fixed crash in is_ignored Removed a lot of log output |
||
#8 | 12565 | Norman Morse |
Integrated from Dev Branch Made ChangeManager into Static Class. Improved close window behavior for when connection is invalid Fixed localOpenFiles not updating on submit |
||
#7 | 12554 | Norman Morse |
Changed OSX DLL checking code. Improved re-connection after restart |
||
#6 | 12553 | Norman Morse |
integrate from internal main Build fixes for EC. Major changes to Configuration and re-initialization code. Bug fixes |
||
#5 | 12512 | Norman Morse | Integrate from Dev branch, preparing for Beta3 release | ||
#4 | 12362 | Norman Morse |
Added Debug Logging for p4log Fixed some path comparison issues. Created a CaseSensitivity test |
||
#3 | 12135 | Norman Morse |
Integrate dev branch changes into main. This code is the basiis of the 2.7 BETA release which provides Unity 5 compatibility |
||
#2 | 11378 | Norman Morse |
P4Config support. Debugging DLL Loading issues |
||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |