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

#352: Add custom map directory file watcher #358

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

alexlambson
Copy link
Contributor

  • Add a file watcher that will detect when a map is added or deleted, then update the game mode dropdown according to the new map list
  • Add and use CustomMapsDirectory field to MapLoader to avoid hard coded strings.
  • Add GetLoadedMapBySha1 to remove some duplicate GameModeMaps.Find().
  • Add a function RefreshGameModeDropdown to modify the dropdown after client is loaded. The function is a bit complicated due to doing inline modifications to the items and keeping the selected mode.

Issue: #352

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

Nightly build for this pull request:

  • artifacts.zip
    This comment is automatic and is meant to allow guests to get latest automatic builds without registering. It is updated on every successful build.

alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Aug 2, 2022
- Add a file watcher that will detect when a map is added or deleted, then update the game mode dropdown according to the new map list
- Add and use `CustomMapsDirectory` field to `MapLoader` to avoid hard coded strings.
- Add `GetLoadedMapBySha1` to remove some duplicate `GameModeMaps.Find()`.
- Add a function `RefreshGameModeDropdown` to modify the dropdown after client is loaded. The function is a bit complicated due to doing inline modifications to the items and keeping the selected mode.

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Aug 2, 2022
- Add a file watcher that will detect when a map is added or deleted, then update the game mode dropdown according to the new map list
- Add and use `CustomMapsDirectory` field to `MapLoader` to avoid hard coded strings.
- Add `GetLoadedMapBySha1` to remove some duplicate `GameModeMaps.Find()`.
- Add a function `RefreshGameModeDropdown` to modify the dropdown after client is loaded. The function is a bit complicated due to doing inline modifications to the items and keeping the selected mode.

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Sep 26, 2022
… then update the game mode dropdown according to the new map list

- Add and use `CustomMapsDirectory` field to `MapLoader` to avoid hard coded strings.
- Add `GetLoadedMapBySha1` to remove some duplicate `GameModeMaps.Find()`.
- Add a function `RefreshGameModeDropdown` to modify the dropdown after client is loaded. The function is a bit complicated due to doing inline modifications to the items and keeping the selected mode.

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Sep 26, 2022
… then update the game mode dropdown according to the new map list

- Add and use `CustomMapsDirectory` field to `MapLoader` to avoid hard coded strings.
- Add `GetLoadedMapBySha1` to remove some duplicate `GameModeMaps.Find()`.
- Add a function `RefreshGameModeDropdown` to modify the dropdown after client is loaded. The function is a bit complicated due to doing inline modifications to the items and keeping the selected mode.

Issue: CnCNet#352
PR: CnCNet#358
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Oct 1, 2022
- Address review fedback
- Use safe path everywhere
- Remove maps if they are renamed and their file extension changes

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Oct 1, 2022
- Address review fedback
- Use safe path everywhere
- Remove maps if they are renamed and their file extension changes

Issue: CnCNet#352
PR: CnCNet#358
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
Copy link
Member

@Metadorius Metadorius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I wrote a(n incomplete I think) review on some stylistical stuff and forgot to publish it, so I'll leave it here, better late than never :P

DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs Outdated Show resolved Hide resolved
DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs Outdated Show resolved Hide resolved
DXMainClient/DXGUI/Multiplayer/GameLobby/GameLobbyBase.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Oct 16, 2022
- Address review feedback
- Use safe path everywhere
- Remove maps if they are renamed and their file extension changes
- Remove unnecessary file watcher filters
- sha1 -> SHA-1

Issue: CnCNet#352
PR: CnCNet#358
@alexlambson
Copy link
Contributor Author

I think I addressed all the feedback

Copy link
Member

@Metadorius Metadorius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You missed some of my earlier stylistical comments and there's something wrong in your code that CI fails, otherwise IMO it's fine.

DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoaderEventArgs.cs Outdated Show resolved Hide resolved
Copy link
Member

@Rampastring Rampastring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this currently handle a case where existing custom maps are modified? If that is done, the SHA1 for the map in question needs to be recalculated. See FileSystemWatcher.Changed event.

DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
DXMainClient/Domain/Multiplayer/MapLoader.cs Outdated Show resolved Hide resolved
@alexlambson
Copy link
Contributor Author

Does this currently handle a case where existing custom maps are modified? If that is done, the SHA1 for the map in question needs to be recalculated. See FileSystemWatcher.Changed event.

It does not, but the map will still load if you try to play it. The Client can already handle that case. I often just save the map in FA2 then just click "play" and it works.

alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Nov 4, 2022
- Address review feedback to fix comments, make handlers private, and switch one-liners to expressions
- Switch MapSharer to download zip to a temp directory to avoid race condition with map file watcher.

Issue: CnCNet#352
PR: CnCNet#358
… then update the game mode dropdown according to the new map list

- Add and use `CustomMapsDirectory` field to `MapLoader` to avoid hard coded strings.
- Add `GetLoadedMapBySha1` to remove some duplicate `GameModeMaps.Find()`.
- Add a function `RefreshGameModeDropdown` to modify the dropdown after client is loaded. The function is a bit complicated due to doing inline modifications to the items and keeping the selected mode.

Issue: CnCNet#352
PR: CnCNet#358
- Address review feedback
- Use safe path everywhere
- Remove maps if they are renamed and their file extension changes
- Remove unnecessary file watcher filters
- sha1 -> SHA-1

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Nov 4, 2022
- Address review feedback to fix comments, make handlers private, and switch one-liners to expressions
- Switch MapSharer to download zip to a temp directory to avoid race condition with map file watcher.
- Add https://mapdb.cncnet.org/search/ to `downloadmap` help message

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Nov 4, 2022
- Address review feedback to fix comments, make handlers private, and switch one-liners to expressions
- Switch MapSharer to download zip to a temp directory to avoid race condition with map file watcher.
- Add https://mapdb.cncnet.org/search/ to `downloadmap` help message

Issue: CnCNet#352
PR: CnCNet#358
alexlambson added a commit to alexlambson/xna-cncnet-client that referenced this pull request Nov 4, 2022
- Address review feedback to fix comments, make handlers private, and switch one-liners to expressions
- Switch MapSharer to download zip to a temp directory to avoid race condition with map file watcher.
- Add https://mapdb.cncnet.org/search/ to `downloadmap` help message

Issue: CnCNet#352
PR: CnCNet#358
@@ -1595,32 +1595,23 @@ private void MapSharer_HandleMapDownloadComplete(SHA1EventArgs e)
{
string mapFileName = MapSharer.GetMapFileName(e.SHA1, e.MapName);
Logger.Log("Map " + mapFileName + " downloaded, parsing.");
string mapPath = "Maps/Custom/" + mapFileName;
Map map = MapLoader.LoadCustomMap(mapPath, out string returnMessage);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now handled by the file watcher to prevent a race condition

@@ -365,18 +365,27 @@ public static string GetMapFileName(string sha1, string mapName)

private static string DownloadMain(string sha1, string myGame, string mapName, out bool success)
{
string customMapsDirectory = SafePath.CombineDirectoryPath(ProgramConstants.GamePath, "Maps", "Custom");
string customMapsPath = SafePath.CombineDirectoryPath(ProgramConstants.GamePath, "Maps", "Custom");
string tempDownloadPath = SafePath.CombineDirectoryPath(ProgramConstants.GamePath, "Maps", "temp");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a temporary download directory so that the filewatcher doesn't prematurely load the .map file before it is fully extracted and renamed.

- Address review feedback to fix comments, make handlers private, and switch one-liners to expressions
- Switch MapSharer to download zip to a temp directory to avoid race condition with map file watcher.
- Add https://mapdb.cncnet.org/search/ to `downloadmap` help message

Issue: CnCNet#352
PR: CnCNet#358
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.

None yet

5 participants