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">
<component name="ChangeListManager">
<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$/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>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -82,7 +81,7 @@
<workItem from="1586792539676" duration="101000" />
<workItem from="1586793017650" duration="506000" />
<workItem from="1586793564564" duration="160000" />
<workItem from="1586793758449" duration="679000" />
<workItem from="1586793758449" duration="1552000" />
</task>
<servers />
</component>

View File

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