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 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; } // Returns whether the system is initialized and we can access perforce public static bool Initialized { 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() { Initialized = false; Initialize(); Initialized = true; } /// <summary> /// Initialize the different parts of P4Connect /// </summary> static public void Initialize() { DateTime startTimestamp = DateTime.Now; SetupRootDirectory(); SetDLLDirectory(); Config.Initialize(); InitializeLogging(); 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(); Debug.Log("P4Connect - Initialization Time: " + deltaTime + " ms"); } } /// <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(); Debug.Log("GetDllDirectory returned error:" + err.ToString()); return null; } return tmp.ToString(); } /// <summary> /// Allow users to override the dll search directory /// </summary> public static void SetDLLDirectory() { if (Application.platform == RuntimePlatform.WindowsEditor) { // Force the DLL search directory as soon as possible string path = Utils.GetBridgeDirectory(); //Debug.Log("SetDLLDirectory to " + path); SetDllDirectory(path); IntPtr href = LoadLibrary("p4bridge"); if (href == IntPtr.Zero) { int err = Marshal.GetLastWin32Error(); Debug.Log("p4bridge LoadLibrary Error: " + err.ToString()); } else { FreeLibrary(href); // Do this or Crash!!! //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)) // Check the modify time on the existing file { if (System.IO.File.GetLastWriteTime(dylibDestPath) < System.IO.File.GetLastWriteTime(dylibSourcePath)) 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"); } } } public static System.Diagnostics.DefaultTraceListener defaultListener; public static void InitializeLogging() { if (Config.EnableLog) { //System.Console.WriteLine("Listeners: " + System.Diagnostics.Trace.Listeners.ToString()); //foreach( System.Diagnostics.TraceListener listener in System.Diagnostics.Trace.Listeners) //{ // System.Console.WriteLine("Listener: " + listener.ToString()); //} System.Diagnostics.Trace.Listeners.RemoveAt(0); defaultListener = new System.Diagnostics.DefaultTraceListener(); defaultListener.LogFileName = Config.LogPath; defaultListener.Name = "p4connect"; // Write the initial trace message to the console trace listener. defaultListener.WriteLine(DateTime.Now.ToString() + " [" + defaultListener.Name + "] - Starting output to trace listener."); // Add the new console trace listener to // the collection of trace listeners. System.Diagnostics.Trace.Listeners.Add(defaultListener); LogFile.SetLoggingFunction(P4ConnectLog); } } // Expose logging from within the bridge public static void P4ConnectLog(int log_level, String source, String message) { string payload = DateTime.Now.ToString() + " lvl: " + log_level.ToString() + " [ " + source + " ] " + message; defaultListener.WriteLine(payload); defaultListener.Flush(); // System.Console.WriteLine(payload); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#29 | 16251 | Norman Morse | Update Dev branch to match reorganization in workshop | ||
#28 | 14840 | Norman Morse | Update dev branch with GA9 fixes | ||
#27 | 14800 | Norman Morse |
Fixed Exception in debug statements Improved performance of pending assets menu on large change sets, some other minor premature optimizations Allowed saving of configuration while Perforce is disabled. Improved restoring connection after recompile. |
||
#26 | 13872 | Norman Morse | Update dev branch from GA.5 release | ||
#25 | 12863 | Norman Morse |
import from main Recently updated from internal Several Bugfixes logging clean up |
||
#24 | 12564 | Norman Morse |
Made ChangeManager into Static Class. Improved close window behavior for when connection is invalid Fixed localOpenFiles not updating on submit |
||
#23 | 12558 | Norman Morse | Integrate from main to dev | ||
#22 | 12510 | Norman Morse |
Another pass at the Configuration UI. password now works but is not obscured in the registry. Fixed browse buttons to use previous paths if set. Removed obsolete fields Removed debugging |
||
#21 | 12473 | Norman Morse | More minor fixes to logging and config | ||
#20 | 12467 | Norman Morse |
Many minor changes to improve logging Added a filter for Console log display where you can select a level Hooked the log file location to the Configuration Log Entry. |
||
#19 | 12445 | Norman Morse |
Integrated log4net and nunit into P4Connect. Still need cleanup and debugging, good enough for dev tree Also added ChangeManager and ChangeLists Classes for future use with multiple changes. |
||
#18 | 12363 | Norman Morse |
Merging //guest/perforce_software/p4connect/src/... to //guest/norman_morse/dev/p4connect/src/... |
||
#17 | 12244 | Norman Morse |
Fixes to Configuration GUI. Fixes to ProgramName and ProgramVer being passed to Connection. |
||
#16 | 12131 | Norman Morse |
Unity 5 fixes for icons and loading the DLL. Needed to use reflection to load the icons. |
||
#15 | 12101 | Norman Morse |
Additional movement towards Unity 5. Still gettting DllNotFound exceptions in 5 |
||
#14 | 12099 | Norman Morse |
Various changes to prepare for Beta Fixed VersionInfo to show changeID Added "additional ignore in config". Updated ReleaseNotes |
||
#13 | 12087 | Norman Morse |
Another Day, another dollar Fixed some bad __except clauses for OSX. Debugging ignore stuff passing pwd in |
||
#12 | 12085 | Norman Morse |
Additional Configuration fields added to dialog. Functionality still needs to be hooked up. |
||
#11 | 12066 | Norman Morse | Debugging Changes from Windows | ||
#10 | 12061 | Norman Morse | Provide logging hooks to the bridge | ||
#9 | 12053 | Norman Morse | Change when restart is needed | ||
#8 | 11853 | Norman Morse | pre release 2.7 workshop dev cleanup | ||
#7 | 11841 | Norman Morse | Multi-platform build for unity 4.x fixup changes | ||
#6 | 11827 | Norman Morse | Fixes to build an DLL locating routines | ||
#5 | 11821 | Norman Morse | Move Unity 5 compatible build from internal dev branch to workshop dev branch. | ||
#4 | 11709 | Norman Morse | Remove some debugging output | ||
#3 | 11323 | Norman Morse | DLL not found debugging | ||
#2 | 11218 | Norman Morse | Print the DLL Search directory | ||
#1 | 10941 | Norman Morse | Create dev branch from workshop | ||
//guest/perforce_software/p4connect/src/P4Connect/P4Connect/P4Connect.Main.cs | |||||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |