-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
base: develop
Are you sure you want to change the base?
Conversation
Nightly build for this pull request:
|
- 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
52edcd8
to
d295e8f
Compare
- 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
d295e8f
to
e75ed55
Compare
… 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
e75ed55
to
664c890
Compare
… 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
664c890
to
96d0a2e
Compare
- Address review fedback - Use safe path everywhere - Remove maps if they are renamed and their file extension changes Issue: CnCNet#352 PR: CnCNet#358
- Address review fedback - Use safe path everywhere - Remove maps if they are renamed and their file extension changes Issue: CnCNet#352 PR: CnCNet#358
dddfee1
to
10e0e6c
Compare
There was a problem hiding this 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
- 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
10e0e6c
to
87c34b5
Compare
I think I addressed all the feedback |
There was a problem hiding this 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.
There was a problem hiding this 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.
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. |
- 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
- 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
537d724
to
1112f70
Compare
674a875
to
1112f70
Compare
- 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
1112f70
to
4af348c
Compare
- 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
4af348c
to
f43f3f5
Compare
@@ -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); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
f43f3f5
to
55bfd57
Compare
CustomMapsDirectory
field toMapLoader
to avoid hard coded strings.GetLoadedMapBySha1
to remove some duplicateGameModeMaps.Find()
.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