Skip to content

Commit

Permalink
add: Save Config on Domain Reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Akeit0 committed Jan 21, 2024
1 parent 993b93b commit 58cab32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static class ConfigurationManager
static ConfigurationManager()
{
NugetConfigFileDirectoryPath = UnityPathHelper.AbsoluteAssetsPath;

Check warning on line 38 in src/NuGetForUnity/Editor/Configuration/ConfigurationManager.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 38 in src/NuGetForUnity/Editor/Configuration/ConfigurationManager.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

NugetConfigFilePath = Path.Combine(NugetConfigFileDirectoryPath, NugetConfigFile.FileName);
}

Expand Down
62 changes: 21 additions & 41 deletions src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,65 +29,45 @@ static UnityPathHelper()
{
AbsoluteAssetsPath = Path.GetFullPath(Application.dataPath);
AbsoluteProjectPath = Path.GetDirectoryName(AbsoluteAssetsPath) ?? throw new InvalidOperationException("Can't detect project root.");


if( installsInPackagesFolder){
var packagePath = Path.Combine(AbsoluteProjectPath, "Packages");
var nugetAssetsPath=Path.Combine(packagePath, "NuGetAssets");
if (!Directory.Exists(nugetAssetsPath))
{
Directory.CreateDirectory(nugetAssetsPath);
}

var packageJsonPath = Path.Combine(nugetAssetsPath, "package.json");
if (!File.Exists(packageJsonPath))
File.WriteAllText(packageJsonPath,
@"{ ""name"": ""com.github-glitchenzo.nugetassets"",""version"": ""1.0.0"",""displayName"": ""NuGetAssets"", ""description"": ""NuGetAssets"", ""dependencies"": {}}");

AbsoluteAssetsPath = nugetAssetsPath;
}
var packagePath = Path.Combine(AbsoluteProjectPath, "Packages");
NugetAssetsPath=Path.Combine(packagePath, "NuGetAssets");
}

private static bool installsInPackagesFolder=EditorPrefs.GetBool("InstallNuGetInPackagesFolder", false);
internal static bool InstallsInPackagesFolder
private static bool installToPackagesFolder=false;

Check warning on line 36 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 36 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 36 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

internal static bool InstallToPackagesFolder

Check warning on line 37 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

{
get=>installsInPackagesFolder;
get=>installToPackagesFolder;
set
{
if(installsInPackagesFolder==value)return;
installsInPackagesFolder = value;
EditorPrefs.SetBool("InstallNuGetInPackagesFolder", true);
var packagePath = Path.Combine(AbsoluteProjectPath, "Packages");
var nugetAssetsPath=Path.Combine(packagePath, "NuGetAssets");
if(installToPackagesFolder==value)return;

Check warning on line 42 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 42 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 42 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

installToPackagesFolder = value;
if (value)
{
if (!Directory.Exists(nugetAssetsPath))
if (!Directory.Exists(NugetAssetsPath))
{
Directory.CreateDirectory(nugetAssetsPath);
Directory.CreateDirectory(NugetAssetsPath);
}

var packageJsonPath = Path.Combine(nugetAssetsPath, "package.json");
var packageJsonPath = Path.Combine(NugetAssetsPath, "package.json");
if (!File.Exists(packageJsonPath))
File.WriteAllText(packageJsonPath,
@"{ ""name"": ""com.akeit0.nugetassets"",""version"": ""1.0.0"",""displayName"": ""NuGetAssets"", ""description"": ""NuGetAssets"", ""dependencies"": {}}");

AbsoluteAssetsPath = nugetAssetsPath;
}
else
{
AbsoluteAssetsPath = Path.GetFullPath(Application.dataPath);
/*if (Directory.Exists(nugetAssetsPath))
{
Directory.Delete(nugetAssetsPath);
}*/
@"{ ""name"": ""com.github-glitchenzo.nugetassets"",""version"": ""1.0.0"",""displayName"": ""NuGetAssets"", ""description"": ""NuGetAssets"", ""dependencies"": {}}");

Check warning on line 55 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

}
}
}

Check warning on line 58 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 58 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

/// <summary>

Check warning on line 59 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 59 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 59 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

/// Gets the absolute path to the Unity-Project 'Assets' directory.
/// Gets the path to the InstallPath directory.
/// </summary>
[NotNull]
internal static string NugetAssetsPath { get; }

Check warning on line 64 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 64 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

Check warning on line 64 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI


Check warning on line 65 in src/NuGetForUnity/Editor/Helper/UnityPathHelper.cs

View workflow job for this annotation

GitHub Actions / Pack .NET Core Global Tool (CLI) and PluginAPI

/// <summary>
/// Gets the absolute path to the NuGetAssets directory.
/// </summary>
[NotNull]
internal static string AbsoluteAssetsPath { get;private set; }
internal static string AbsoluteAssetsPath { get; }

/// <summary>
/// Gets the absolute path to the Unity-Project root directory.
Expand Down

0 comments on commit 58cab32

Please sign in to comment.