Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/dev_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ jobs:
- name: Restore NuGet Packages
run: nuget restore Revit_glTF_Exporter.sln

- name: Setting new version to the App.config file
- name: Setting new version to the config file
run: |
(Get-Content Common_glTF_Exporter/App.config) -replace 'key="version" value="[^"]+"', "key=`"version`" value=`"$env:FULL_VERSION`"" | Out-File -encoding ASCII Common_glTF_Exporter/App.config
(Get-Content Common_glTF_Exporter/Utils/SettingsConfig.cs) -replace '0.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Common_glTF_Exporter/Utils/SettingsConfig.cs

- name: Configuring Key
run: |
$apiUrlKey = "${{ secrets.EVERSE_GLTF_EXPORTER_APIKEY }}"
(Get-Content Common_glTF_Exporter/Utils/SettingsConfig.cs) -replace 'PlaceHolderApiKey', apiUrlKey | Out-File -encoding ASCII Common_glTF_Exporter/Utils/SettingsConfig.cs
shell: pwsh

- name: Setting new version to the AssemblyInfo 2019
run: |
(Get-Content Revit_glTF_Exporter_2019/Properties/AssemblyInfo.cs) -replace '1.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Revit_glTF_Exporter_2019/Properties/AssemblyInfo.cs
Expand Down Expand Up @@ -106,10 +112,6 @@ jobs:
run: |
(Get-Content Common_glTF_Exporter/PackageContents.xml) -replace '1.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Common_glTF_Exporter/PackageContents.xml

- name: Configuring Key
run: |
(Get-Content Common_glTF_Exporter/App.config) -replace 'key="apikey" value="[^"]+"', "key=`"apikey`" value=`"${{ secrets.EVERSE_GLTF_EXPORTER_APIKEY }}`"" | Out-File -encoding ASCII Common_glTF_Exporter/App.config

- name: Configuring API URL
run: |
$apiUrl = "${{ secrets.EVERSE_GLTF_EXPORTER_APIURL }}"
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/dev_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ jobs:
- name: Restore NuGet Packages
run: nuget restore Revit_glTF_Exporter.sln

- name: Setting new version to the App.config file
- name: Setting new version to the config file
run: |
(Get-Content Common_glTF_Exporter/App.config) -replace 'key="version" value="[^"]+"', "key=`"version`" value=`"$env:FULL_VERSION`"" | Out-File -encoding ASCII Common_glTF_Exporter/App.config
(Get-Content Common_glTF_Exporter/Utils/SettingsConfig.cs) -replace '0.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Common_glTF_Exporter/Utils/SettingsConfig.cs

- name: Configuring Key
run: |
$apiUrlKey = "${{ secrets.EVERSE_GLTF_EXPORTER_APIKEY }}"
(Get-Content Common_glTF_Exporter/Utils/SettingsConfig.cs) -replace 'PlaceHolderApiKey', apiUrlKey | Out-File -encoding ASCII Common_glTF_Exporter/Utils/SettingsConfig.cs
shell: pwsh

- name: Setting new version to the AssemblyInfo 2019
run: |
(Get-Content Revit_glTF_Exporter_2019/Properties/AssemblyInfo.cs) -replace '1.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Revit_glTF_Exporter_2019/Properties/AssemblyInfo.cs
Expand Down Expand Up @@ -104,10 +110,6 @@ jobs:
run: |
(Get-Content Common_glTF_Exporter/PackageContents.xml) -replace '1.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Common_glTF_Exporter/PackageContents.xml

- name: Configuring Key
run: |
(Get-Content Common_glTF_Exporter/App.config) -replace 'key="apikey" value="[^"]+"', "key=`"apikey`" value=`"${{ secrets.EVERSE_GLTF_EXPORTER_APIKEY }}`"" | Out-File -encoding ASCII Common_glTF_Exporter/App.config

- name: Configuring API URL
run: |
$apiUrl = "${{ secrets.EVERSE_GLTF_EXPORTER_APIURL }}"
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/production_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,16 @@ jobs:
- name: Restore NuGet Packages
run: nuget restore Revit_glTF_Exporter.sln

- name: Setting new version to the App.config file
- name: Setting new version to the config file
run: |
(Get-Content Common_glTF_Exporter/App.config) -replace 'key="version" value="[^"]+"', "key=`"version`" value=`"$env:FULL_VERSION`"" | Out-File -encoding ASCII Common_glTF_Exporter/App.config
(Get-Content Common_glTF_Exporter/Utils/SettingsConfig.cs) -replace '0.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Common_glTF_Exporter/Utils/SettingsConfig.cs

- name: Configuring Key
run: |
$apiUrlKey = "${{ secrets.EVERSE_GLTF_EXPORTER_APIKEY }}"
(Get-Content Common_glTF_Exporter/Utils/SettingsConfig.cs) -replace 'PlaceHolderApiKey', apiUrlKey | Out-File -encoding ASCII Common_glTF_Exporter/Utils/SettingsConfig.cs
shell: pwsh

- name: Setting new version to the AssemblyInfo 2019
run: |
(Get-Content Revit_glTF_Exporter_2019/Properties/AssemblyInfo.cs) -replace '1.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Revit_glTF_Exporter_2019/Properties/AssemblyInfo.cs
Expand Down Expand Up @@ -131,10 +137,6 @@ jobs:
run: |
(Get-Content Common_glTF_Exporter/PackageContents.xml) -replace '1.0.0', $env:FULL_VERSION | Out-File -encoding ASCII Common_glTF_Exporter/PackageContents.xml

- name: Configuring Key
run: |
(Get-Content Common_glTF_Exporter/App.config) -replace 'key="apikey" value="[^"]+"', "key=`"apikey`" value=`"${{ secrets.EVERSE_GLTF_EXPORTER_APIKEY }}`"" | Out-File -encoding ASCII Common_glTF_Exporter/App.config

- name: Configuring API URL
run: |
$apiUrl = "${{ secrets.EVERSE_GLTF_EXPORTER_APIURL }}"
Expand Down
26 changes: 0 additions & 26 deletions Common_glTF_Exporter/App.config

This file was deleted.

3 changes: 0 additions & 3 deletions Common_glTF_Exporter/Common_glTF_Exporter.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,4 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)App.config" />
</ItemGroup>
</Project>
189 changes: 96 additions & 93 deletions Common_glTF_Exporter/Utils/SettingsConfig.cs
Original file line number Diff line number Diff line change
@@ -1,129 +1,132 @@
namespace Common_glTF_Exporter.Utils
{
using Autodesk.Internal.InfoCenter;
using System.Configuration;
using System.IO;
using System.Reflection;
using Configuration = System.Configuration.Configuration;
using Autodesk.Revit.DB;
using System;
using System.Xml;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Xml;

namespace Common_glTF_Exporter.Utils
{
public static class SettingsConfig
{
#if REVIT2025 || REVIT2026

private static string programDataLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
private static string appSettingsFile = string.Concat(programDataLocation, "\\Autodesk\\ApplicationPlugins\\leia.bundle\\Contents\\2025\\Leia_glTF_Exporter.dll.config");
private static readonly string _configDir =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Leia");

private static readonly string _configFile =
Path.Combine(_configDir, "leia.config");

private static readonly string _currentVersion = "0.0.0";
private static readonly string _currentApiKey= "PlaceHolderApiKey";

private static readonly object _locker = new object();

static SettingsConfig()
{
// Ensure folder exists
if (!Directory.Exists(_configDir))
Directory.CreateDirectory(_configDir);

// Ensure file exists with defaults
if (!File.Exists(_configFile))
CreateDefaultConfig();
}

public static string GetValue(string key)
{
try
lock (_locker)
{
XmlDocument doc = new XmlDocument();
doc.Load(appSettingsFile);

XmlNode node = doc.SelectSingleNode($"//appSettings/add[@key='{key}']");
if (node != null)
try
{
return node.Attributes["value"].Value;
Configuration config = OpenConfig();
KeyValueConfigurationElement setting = config.AppSettings.Settings[key];
return setting != null ? setting.Value : null;
}
else
catch (Exception ex)
{
throw new KeyNotFoundException($"Key '{key}' not found in configuration file.");
throw new InvalidOperationException(
$"Error retrieving value for key '{key}'.", ex);
}
}
catch (Exception ex)
{
// Log or handle the exception as needed
throw new InvalidOperationException($"Error retrieving value for key '{key}'", ex);
}
}

public static void SetValue(string key, string value)
{
try
lock (_locker)
{
XmlDocument doc = new XmlDocument();
doc.Load(appSettingsFile);

XmlNode node = doc.SelectSingleNode($"//appSettings/add[@key='{key}']");
if (node != null)
try
{
node.Attributes["value"].Value = value;
Configuration config = OpenConfig();
KeyValueConfigurationCollection settings = config.AppSettings.Settings;

if (settings[key] == null)
settings.Add(key, value);
else
settings[key].Value = value;

config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
else
catch (Exception ex)
{
XmlNode appSettingsNode = doc.SelectSingleNode("//appSettings");
if (appSettingsNode == null)
{
appSettingsNode = doc.CreateElement("appSettings");
doc.DocumentElement.AppendChild(appSettingsNode);
}

XmlElement addElement = doc.CreateElement("add");
addElement.SetAttribute("key", key);
addElement.SetAttribute("value", value);
appSettingsNode.AppendChild(addElement);
throw new InvalidOperationException(
$"Error setting value for key '{key}'.", ex);
}

doc.Save(appSettingsFile);
}
catch (Exception ex)
{
// Log or handle the exception as needed
throw new InvalidOperationException($"Error setting value for key '{key}'", ex);
}
}

#else

private static readonly string BinaryLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private static string appSettingsName = string.Concat(Assembly.GetExecutingAssembly().GetName().Name, ".dll.config");
private static string appSettingsFile = System.IO.Path.Combine(BinaryLocation, appSettingsName);

public static string GetValue(string key)
private static Configuration OpenConfig()
{
try
{
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = appSettingsFile }, ConfigurationUserLevel.None);
return configuration.AppSettings.Settings[key].Value;
}
catch (Exception ex)
{
// Log or handle the exception as needed
throw new InvalidOperationException($"Error retrieving value for key '{key}'", ex);
}
var map = new ExeConfigurationFileMap { ExeConfigFilename = _configFile };
return ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
}

public static void SetValue(string key, string value)
/// <summary>
/// Creates leia.config with the requested default keys/values.
/// </summary>
private static void CreateDefaultConfig()
{
try
{
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = appSettingsFile }, ConfigurationUserLevel.None);
configuration.AppSettings.Settings[key].Value = value;
configuration.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appSettings");
}
catch (Exception ex)
// Your requested defaults (removed the duplicated "runs" key to avoid errors).
var defaults = new Dictionary<string, string>
{
// Log or handle the exception as needed
throw new InvalidOperationException($"Error setting value for key '{key}'", ex);
}
}
#endif
{ "materials", "true" },
{ "format", "gltf" },
{ "normals", "false" },
{ "levels", "false" },
{ "lights", "false" },
{ "grids", "false" },
{ "batchId", "false" },
{ "properties", "false" },
{ "relocateTo0", "false" },
{ "flipAxis", "true" },
{ "units", "null" },
{ "compression", "none" },
{ "path", @"C:\Users\User\Desktop" }, // adjust if you need
{ "fileName", "3dExport" },
{ "runs", "0" },
{ "version", _currentVersion },
{ "user", "user01" },
{ "release", "0" },
{ "isRFA", "false" },
{ "apikey", _currentApiKey }
};

private static string GetBinaryLocation()
{
string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var doc = new XmlDocument();
var decl = doc.CreateXmlDeclaration("1.0", "utf-8", null);
doc.AppendChild(decl);

XmlElement configuration = doc.CreateElement("configuration");
doc.AppendChild(configuration);

XmlElement appSettings = doc.CreateElement("appSettings");
configuration.AppendChild(appSettings);

if (string.IsNullOrEmpty(location))
foreach (var kvp in defaults)
{
UriBuilder uri = new UriBuilder(Assembly.GetExecutingAssembly().CodeBase);
location = Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path));
XmlElement add = doc.CreateElement("add");
add.SetAttribute("key", kvp.Key);
add.SetAttribute("value", kvp.Value);
appSettings.AppendChild(add);
}

return location;
doc.Save(_configFile);
}
}
}
Loading