Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy built-in resources to "OutputPath" only when needed #632

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

pzhlkj6612
Copy link
Contributor

Hi.

Commit message

Copy built-in resources to "OutputPath" only when needed

The conditions are:

- It's being debugged;
- It's DXMainClient;
- It's cross-targeting build ('$(TargetFramework)' == ''). Don't know the whole story, just from my guess:
    - https://github.com/dotnet/msbuild/blob/b497794a81585d40ba5401acde02200f7b7d863b/src/Tasks/Microsoft.Managed.Before.targets
    - https://github.com/dotnet/msbuild/blob/b497794a81585d40ba5401acde02200f7b7d863b/src/Tasks/Microsoft.Common.CrossTargeting.targets
- No "ClientDefinitions.ini" in destination.

Why

I've seen the "SUN.INI" file multiple times when playing with YR client. So today I did a search in the project root directory:

$ find . -path '*/bin/*' -name 'SUN.ini'
./ClientCore/bin/Debug/YR/WindowsDX/net48/SUN.ini
./ClientCore/bin/Debug/YR/WindowsDX/net8.0-windows/SUN.ini
./ClientCore/bin/Debug/YR/WindowsDX/SUN.ini
./ClientGUI/bin/Debug/YR/WindowsDX/net48/SUN.ini
./ClientGUI/bin/Debug/YR/WindowsDX/net8.0-windows/SUN.ini
./ClientGUI/bin/Debug/YR/WindowsDX/SUN.ini
./ClientUpdater/bin/Debug/YR/WindowsDX/net48/SUN.ini
./ClientUpdater/bin/Debug/YR/WindowsDX/net8.0/SUN.ini
./ClientUpdater/bin/Debug/YR/WindowsDX/SUN.ini
./DTAConfig/bin/Debug/YR/WindowsDX/net48/SUN.ini
./DTAConfig/bin/Debug/YR/WindowsDX/net8.0-windows/SUN.ini
./DTAConfig/bin/Debug/YR/WindowsDX/SUN.ini
./DXMainClient/bin/Debug/YR/WindowsDX/net48/SUN.ini
./DXMainClient/bin/Debug/YR/WindowsDX/net8.0-windows/SUN.ini
./DXMainClient/bin/Debug/YR/WindowsDX/SUN.ini
./SecondStageUpdater/bin/Debug/YR/WindowsDX/net48/SUN.ini
./SecondStageUpdater/bin/Debug/YR/WindowsDX/net48/Updater/SUN.ini
./SecondStageUpdater/bin/Debug/YR/WindowsDX/net8.0/SUN.ini
./SecondStageUpdater/bin/Debug/YR/WindowsDX/net8.0/Updater/SUN.ini
./TranslationNotifierGenerator/bin/Debug/YR/WindowsDX/netstandard2.0/SUN.ini
./TranslationNotifierGenerator/bin/Debug/YR/WindowsDX/SUN.ini

Oh, they are too many, aren't they?

After doing some testing, I think we need to tweak the "CopyResources" target by adding more conditions, so I did it in this PR.

Change

After applying this PR, the built-in resources will be copied to the bin\Debug\$(Game)\$(Engine) directory, so the binary of both net8.0 and non-net8.0 will share the same game files.

Question

I can see the duplicated SearchResourcesDir(string startupPath) functions in both DXMainClient and ClientCore modules:

/// <summary>
/// This method finds the "Resources" directory by traversing the directory tree upwards from the startup path.
/// </summary>
/// <remarks>
/// This method is needed by both ClientCore and DXMainClient. However, since it is usually called at the very beginning,
/// where DXMainClient could not refer to ClientCore, this method is copied to both projects.
/// Remember to keep <see cref="ClientCore.ProgramConstants.SearchResourcesDir"/> and <see cref="DTAClient.Program.SearchResourcesDir"/> consistent if you have modified its source codes.
/// </remarks>
private static string SearchResourcesDir(string startupPath)
{
DirectoryInfo currentDir = new(startupPath);
for (int i = 0; i < 3; i++)
{
// Determine if currentDir is the "Resources" folder
if (currentDir.Name.ToLowerInvariant() == "Resources".ToLowerInvariant())
return currentDir.FullName;
// Additional check. This makes developers to debug the client inside Visual Studio a little bit easier.
DirectoryInfo resourcesDir = currentDir.GetDirectories("Resources", SearchOption.TopDirectoryOnly).FirstOrDefault();
if (resourcesDir is not null)
return resourcesDir.FullName;
currentDir = currentDir.Parent;
}
throw new Exception("Could not find Resources directory.");
}

My question is: do we need those resources during debugging ClientCore? If so, I think I may need to change the condition statement.

The conditions are:

- It's being debugged;
- It's DXMainClient;
- It's cross-targeting build ('$(TargetFramework)' == ''). Don't know the whole story, just from my guess:
    - https://github.com/dotnet/msbuild/blob/b497794a81585d40ba5401acde02200f7b7d863b/src/Tasks/Microsoft.Managed.Before.targets
    - https://github.com/dotnet/msbuild/blob/b497794a81585d40ba5401acde02200f7b7d863b/src/Tasks/Microsoft.Common.CrossTargeting.targets
- No "ClientDefinitions.ini" in destination.
Copy link

github-actions bot commented Jan 8, 2025

Nightly build for this pull request:

The conditions are:

- It's being debugged;
- It's ClientCore or DTAConfig or DXMainClient;
- It's cross-targeting build ('$(TargetFramework)' == ''). Don't know the whole story, just from my guess:
    - https://github.com/dotnet/msbuild/blob/b497794a81585d40ba5401acde02200f7b7d863b/src/Tasks/Microsoft.Managed.Before.targets
    - https://github.com/dotnet/msbuild/blob/b497794a81585d40ba5401acde02200f7b7d863b/src/Tasks/Microsoft.Common.CrossTargeting.targets
- No "ClientDefinitions.ini" in destination.
@pzhlkj6612
Copy link
Contributor Author

f1fb5cf:

Without the $(MSBuildProjectName) check, we will get copied resources as the follows:

$ find . -path '*/bin/*' -name 'SUN.ini'
./ClientCore/bin/Debug/YR/WindowsDX/SUN.ini
./ClientGUI/bin/Debug/YR/WindowsDX/SUN.ini
./ClientUpdater/bin/Debug/YR/WindowsDX/SUN.ini
./DTAConfig/bin/Debug/YR/WindowsDX/SUN.ini
./DXMainClient/bin/Debug/YR/WindowsDX/SUN.ini
./TranslationNotifierGenerator/bin/Debug/YR/WindowsDX/SUN.ini
for d in 'ClientCore' 'ClientGUI' 'ClientUpdater' 'DTAConfig' 'DXMainClient' 'TranslationNotifierGenerator'; do
    echo "dir($d) = $(grep -rnw 'Resources' --include '*.cs' ./$d | wc -l)";
done
dir(ClientCore) = 22
dir(ClientGUI) = 0
dir(ClientUpdater) = 4
dir(DTAConfig) = 5
dir(DXMainClient) = 14
dir(TranslationNotifierGenerator) = 0

After briefly reading the code of the above projects, I think we only need the copied resources for these projects:

  • ClientCore
  • DTAConfig
  • DXMainClient

.

@pzhlkj6612 pzhlkj6612 marked this pull request as draft January 31, 2025 16:13
@SadPencil SadPencil modified the milestones: 2.11.7.0, long term Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants