Skip to content

Commit

Permalink
Make settings files path relative to .dll location
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Seagrave committed Feb 5, 2025
1 parent 3823909 commit 5e88820
Show file tree
Hide file tree
Showing 9 changed files with 5,080 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/CCDSR/vcpkg_installed/x86-windows-static
20 changes: 17 additions & 3 deletions CCDSR/CCDSRPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,32 @@ static bool isValidData(Json::Value _value)
return true;
}

static std::filesystem::path fetchDllPath()
{
char DllPathFile[_MAX_PATH];
if (GetModuleFileNameA(HINSTANCE(&__ImageBase), DllPathFile, sizeof(DllPathFile)) == 0) {
return {}; // Return empty if GetModuleFileNameA fails
}

// Use filesystem to get the parent directory path
std::filesystem::path dllPath = DllPathFile;

auto p = dllPath.parent_path();
return p;
}

CCDSRPlugIn::CCDSRPlugIn(void)
: CPlugIn(EuroScopePlugIn::COMPATIBILITY_CODE,
"CCDS-R Plugin",
"1.0.0",
"1.1.0",
"Joshua Seagrave",
"CC BY-NC-SA 4.0")
{

RegisterTagItemType("CCDS-R Callsign/Squawk", TAG_ITEM_CCDSR_CALLSIGN); // registering tag items and names in ES.
RegisterTagItemType("CCDS-R Label", TAG_ITEM_CCDSR_LABEL);

std::string filePath = "UK/Data/Plugin/CCDS-R/Settings/conversions.json"; // local path to the CCDS-R config file.
auto filePath = fetchDllPath() += "\\Settings\\conversions.json"; // local path to the CCDS-R config file.

std::ifstream conversionsFile(filePath, std::ifstream::binary); // opens a filestream to read the JSON file.

Expand All @@ -46,7 +60,7 @@ CCDSRPlugIn::CCDSRPlugIn(void)
pMyPlugIn->DisplayUserMessage( // send a message to the user notifying them of the problem.
"CCDS-R",
"",
("Error finding " + filePath + ". Custom Code-callsign conversions and labels will be non-functional.").c_str(),
("Error finding " + filePath.string() + ". Custom Code-callsign conversions and labels will be non-functional.").c_str(),
true,
true,
true,
Expand Down
105 changes: 101 additions & 4 deletions CCDSR/CCDSRPlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Make|Win32">
<Configuration>Make</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Make|x64">
<Configuration>Make</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
Expand Down Expand Up @@ -40,6 +48,13 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
Expand All @@ -53,6 +68,13 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Make|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
Expand All @@ -64,24 +86,46 @@
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Make|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>CCDS-R</TargetName>
<OutDir>C:\Users\josha\Documents\EuroScope\UK\Data\Plugin\CCDS-R\</OutDir>
<OutDir>$(SolutionDir)\$(Configuration)\</OutDir>
<EnableClangTidyCodeAnalysis>true</EnableClangTidyCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'">
<TargetName>CCDS-R</TargetName>
<OutDir>$(SolutionDir)\$(Configuration)\</OutDir>
<EnableClangTidyCodeAnalysis>true</EnableClangTidyCodeAnalysis>
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgTriplet>x86-windows</VcpkgTriplet>
<VcpkgInstalledDir>
</VcpkgInstalledDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'" Label="Vcpkg">
<VcpkgUseStatic>true</VcpkgUseStatic>
<VcpkgTriplet>x86-windows</VcpkgTriplet>
<VcpkgInstalledDir />
</PropertyGroup>
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<VcpkgUseStatic>true</VcpkgUseStatic>
</PropertyGroup>
<PropertyGroup Label="Vcpkg">
<VcpkgEnableManifest>true</VcpkgEnableManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down Expand Up @@ -112,7 +156,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>C:\Users\josha\Documents\ESPlugInFiles\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)\Externals\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
Expand All @@ -122,8 +166,39 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>C:\Users\josha\Documents\ESPlugInFiles\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>EuroScopePlugInDll.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)\Externals\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>EuroScopePlugInDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Make|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;TDBCALLSIGNS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>$(SolutionDir)\Externals\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<AdditionalLibraryDirectories>$(SolutionDir)\Externals\lib</AdditionalLibraryDirectories>
<AdditionalDependencies>EuroScopePlugInDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary />
<NoEntryPoint>false</NoEntryPoint>
<AdditionalOptions>/NOIMPLIB /NOEXP %(AdditionalOptions)</AdditionalOptions>
</Link>
<PostBuildEvent>
<Command>
Expand Down Expand Up @@ -164,6 +239,25 @@
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Make|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;TDBCALLSIGNS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="StdAfx.h" />
Expand All @@ -176,8 +270,11 @@
</ClCompile>
<ClCompile Include="CCDSRPlugin.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Use</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Make|Win32'">Use</PrecompiledHeader>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Make|Win32'">
</AdditionalOptions>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">StdAfx.h</PrecompiledHeaderFile>
</ClCompile>
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions CCDSR/StdAfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
#include <string>
#include <json/json.h>
#include <fstream>
#include <filesystem>
#include <Windows.h>

extern "C" IMAGE_DOS_HEADER __ImageBase;
#endif //PCH_H
5 changes: 5 additions & 0 deletions CCDSR/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": [
"jsoncpp"
]
}
20 changes: 7 additions & 13 deletions CCDSRPlugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CCDSRPlugin", "CCDSR\CCDSRPlugin.vcxproj", "{052371CD-5884-40EF-A09B-E55D155BD33F}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CCDS-R", "CCDSR\CCDSRPlugin.vcxproj", "{052371CD-5884-40EF-A09B-E55D155BD33F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
Make|x64 = Make|x64
Make|x86 = Make|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{052371CD-5884-40EF-A09B-E55D155BD33F}.Debug|x64.ActiveCfg = Debug|x64
{052371CD-5884-40EF-A09B-E55D155BD33F}.Debug|x64.Build.0 = Debug|x64
{052371CD-5884-40EF-A09B-E55D155BD33F}.Debug|x86.ActiveCfg = Debug|Win32
{052371CD-5884-40EF-A09B-E55D155BD33F}.Debug|x86.Build.0 = Debug|Win32
{052371CD-5884-40EF-A09B-E55D155BD33F}.Release|x64.ActiveCfg = Release|x64
{052371CD-5884-40EF-A09B-E55D155BD33F}.Release|x64.Build.0 = Release|x64
{052371CD-5884-40EF-A09B-E55D155BD33F}.Release|x86.ActiveCfg = Release|Win32
{052371CD-5884-40EF-A09B-E55D155BD33F}.Release|x86.Build.0 = Release|Win32
{052371CD-5884-40EF-A09B-E55D155BD33F}.Make|x64.ActiveCfg = Make|x64
{052371CD-5884-40EF-A09B-E55D155BD33F}.Make|x64.Build.0 = Make|x64
{052371CD-5884-40EF-A09B-E55D155BD33F}.Make|x86.ActiveCfg = Make|Win32
{052371CD-5884-40EF-A09B-E55D155BD33F}.Make|x86.Build.0 = Make|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit 5e88820

Please sign in to comment.