SyncSolution

This commit is contained in:
nakano yosuke 2020-04-14 01:31:34 +09:00
parent 450bc133b8
commit 259075c83a
2 changed files with 50 additions and 82 deletions

View File

@ -2,9 +2,8 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="f71251e0-52ab-4cea-859f-4c363c01a121" name="Default Changelist" comment=""> <list default="true" id="f71251e0-52ab-4cea-859f-4c363c01a121" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/contentModel.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001/Unity.InternalAPIEditorBridgeDev.001.asmdef" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001/Unity.InternalAPIEditorBridgeDev.001.asmdef" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/AsmdefHelper/SyncSolution/Editor/SyncSolutionUtilities.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/AsmdefHelper/SyncSolution/Editor/SyncSolutionUtilities.cs" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -82,7 +81,7 @@
<workItem from="1586792539676" duration="101000" /> <workItem from="1586792539676" duration="101000" />
<workItem from="1586793017650" duration="506000" /> <workItem from="1586793017650" duration="506000" />
<workItem from="1586793564564" duration="160000" /> <workItem from="1586793564564" duration="160000" />
<workItem from="1586793758449" duration="679000" /> <workItem from="1586793758449" duration="1552000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -1,93 +1,62 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using UnityEditor; using UnityEditor;
using UnityEditor.VisualStudioIntegration;
using UnityEngine; using UnityEngine;
//https://forum.unity.com/threads/solved-unity-not-generating-sln-file-from-assets-open-c-project.538487/ // https://forum.unity.com/threads/solved-unity-not-generating-sln-file-from-assets-open-c-project.538487/
namespace EditorUtilities.Solution // Thank you Flexford!
{ namespace AsmdeffHelper.SyncSolution {
public static class SyncSolutionUtilities public static class SyncSolutionUtilities {
{ static SolutionSynchronizer synchronizer;
private static Type _syncVSType;
private static MethodInfo _syncSolutionMethodInfo;
private static FieldInfo _synchronizerField; static SyncSolutionUtilities() {
private static object _synchronizerObject; synchronizer = SyncVS.Synchronizer;
private static Type _synchronizerType; }
private static MethodInfo _synchronizerSyncMethodInfo;
static SyncSolutionUtilities() [MenuItem("Window/Asmdef Helper/Sync C# Solution", priority = 1000000)]
{ public static void Sync() {
_syncVSType = Type.GetType("UnityEditor.SyncVS,UnityEditor"); Sync(true);
_synchronizerField = _syncVSType.GetField("Synchronizer", BindingFlags.NonPublic | BindingFlags.Static); }
_syncSolutionMethodInfo = _syncVSType.GetMethod("SyncSolution", BindingFlags.Public | BindingFlags.Static);
_synchronizerObject = _synchronizerField.GetValue(_syncVSType); static void Sync(bool logsEnabled) {
_synchronizerType = _synchronizerObject.GetType(); CleanOldFiles(logsEnabled);
_synchronizerSyncMethodInfo = _synchronizerType.GetMethod("Sync", BindingFlags.Public | BindingFlags.Instance); Call_SyncSolution(logsEnabled);
} Call_SynchronizerSync(logsEnabled);
}
[MenuItem("Assets/Sync C# Solution", priority = 1000000)] static void CleanOldFiles(bool logsEnabled) {
public static void Sync() var assetsDirectoryInfo = new DirectoryInfo(Application.dataPath);
{ var projectDirectoryInfo = assetsDirectoryInfo.Parent;
Sync(true);
}
public static void Sync(bool logsEnabled) var files = GetFilesByExtensions(projectDirectoryInfo, "*.sln", "*.csproj");
{ foreach (var file in files) {
CleanOldFiles(logsEnabled); if (logsEnabled) {
Call_SyncSolution(logsEnabled); Debug.Log($"Remove old solution file: {file.Name}");
Call_SynchronizerSync(logsEnabled); }
} file.Delete();
}
}
private static void CleanOldFiles(bool logsEnabled) static void Call_SyncSolution(bool logsEnabled) {
{ if (logsEnabled) {
DirectoryInfo assetsDirectoryInfo = new DirectoryInfo(Application.dataPath); Debug.Log($"Coll method: SyncVS.Sync()");
DirectoryInfo projectDirectoryInfo = assetsDirectoryInfo.Parent; }
SyncVS.SyncSolution();
}
IEnumerable<FileInfo> files = GetFilesByExtensions(projectDirectoryInfo, "*.sln", "*.csproj"); static void Call_SynchronizerSync(bool logsEnabled) {
foreach(FileInfo file in files) if (logsEnabled) {
{ Debug.Log($"Coll method: SyncVS.Synchronizer.Sync()");
if(logsEnabled) }
{ synchronizer?.Sync();
Debug.Log($"Remove old solution file: {file.Name}"); }
}
file.Delete();
}
}
private static void Call_SyncSolution(bool logsEnabled) static IEnumerable<FileInfo> GetFilesByExtensions(DirectoryInfo dir, params string[] extensions) {
{ extensions = extensions ?? new[] { "*" };
if(logsEnabled) var files = Enumerable.Empty<FileInfo>();
{ return extensions.Aggregate(files, (current, ext) => current.Concat(dir.GetFiles(ext)));
Debug.Log($"Coll method: SyncVS.Sync()"); }
} }
_syncSolutionMethodInfo.Invoke(null, null);
}
private static void Call_SynchronizerSync(bool logsEnabled)
{
if(logsEnabled)
{
Debug.Log($"Coll method: SyncVS.Synchronizer.Sync()");
}
_synchronizerSyncMethodInfo.Invoke(_synchronizerObject, null);
}
private static IEnumerable<FileInfo> GetFilesByExtensions(DirectoryInfo dir, params string[] extensions)
{
extensions = extensions ?? new []{"*"};
IEnumerable<FileInfo> files = Enumerable.Empty<FileInfo>();
foreach(string ext in extensions)
{
files = files.Concat(dir.GetFiles(ext));
}
return files;
}
}
} }