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

Store downloaded maps unzipped #8622

Merged
merged 5 commits into from
Jan 13, 2021
Merged

Conversation

DanVanAtta
Copy link
Member

Updates code to extract from zip existing and newly downloaded
maps. Various code paths to load maps from zip can then be
removed.

Testing

Screens Shots

Additional Notes to Reviewer

  • Ready to get feedback
  • Still a draft while some final testing is done
  • Most of the submitted code is polished, but could still be rough in a few places

Release Note

UPDATE|Downloaded maps are now extracted and stored as flat files rather than as zipped files.

Updates code to extract from zip existing and newly downloaded
maps. Various code paths to load maps from zip can then be
removed.
@DanVanAtta DanVanAtta marked this pull request as draft January 12, 2021 04:08
Copy link
Member

@RoiEXLab RoiEXLab left a comment

Choose a reason for hiding this comment

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

I must admit I was sceptical when I started reviewing this PR if we really gain something from this change, but after having a look at the changes I'm convinced that this is a step in the right direction.

@@ -47,27 +41,6 @@
new File(userMapsFolder, normalizedMapName));
Copy link
Member

Choose a reason for hiding this comment

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

Not directly related to this PR, but I start wondering how much code we could end up saving by migrating away from java.io.File to java.nio.Path.
This simple method could get simplified to something like:

static List<Path> getCandidatePaths(final String mapName, final Path userMapsFolder) {
    Preconditions.checkNotNull(mapName);

    final String normalizedMapName = normalizeMapName(mapName) + "-master";
    return List.of(
        userMapsFolder.resolve(Path.of(mapName, "map")),
        userMapsFolder.resolve(mapName),
        userMapsFolder.resolve(Path.of(normalizedMapName, "map")),
        userMapsFolder.resolve(normalizedMapName));
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Not having to deal with file separator is a win. We likely should be preferring path where we can. Working in existing code is a bit odd as it's mixed now, but I'm certainly on board to convert and use Path in new code.

@codecov
Copy link

codecov bot commented Jan 13, 2021

Codecov Report

Merging #8622 (cb76162) into master (22f0c8d) will decrease coverage by 0.03%.
The diff coverage is 0.96%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #8622      +/-   ##
============================================
- Coverage     24.92%   24.88%   -0.04%     
+ Complexity     7375     7365      -10     
============================================
  Files          1291     1291              
  Lines         80312    80359      +47     
  Branches      11006    11011       +5     
============================================
- Hits          20017    19997      -20     
- Misses        58221    58289      +68     
+ Partials       2074     2073       -1     
Impacted Files Coverage Δ Complexity Δ
...ne/framework/map/download/DownloadCoordinator.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...amework/map/download/FileSystemAccessStrategy.java 1.69% <0.00%> (-6.93%) 1.00 <0.00> (-3.00)
.../system/loader/AvailableGamesFileSystemReader.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...amework/map/file/system/loader/DownloadedMaps.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...rk/map/file/system/loader/FileSystemMapFinder.java 76.47% <0.00%> (+6.90%) 6.00 <0.00> (-1.00) ⬆️
...rk/map/file/system/loader/ZippedMapsExtractor.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...in/java/games/strategy/triplea/ResourceLoader.java 9.37% <0.00%> (+1.78%) 4.00 <0.00> (ø)
...ras/src/main/java/org/triplea/io/ZipExtractor.java 42.85% <0.00%> (-1.59%) 6.00 <0.00> (ø)
...engine/framework/map/download/MapDownloadList.java 77.27% <100.00%> (ø) 9.00 <0.00> (ø)
...framework/map/download/DownloadFileProperties.java 0.00% <0.00%> (-50.00%) 0.00% <0.00%> (-6.00%)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 22f0c8d...cb76162. Read the comment docs.

@DanVanAtta DanVanAtta marked this pull request as ready for review January 13, 2021 05:47
@DanVanAtta DanVanAtta merged commit c10e684 into master Jan 13, 2021
@DanVanAtta DanVanAtta deleted the store-maps-as-expanded-zips branch January 13, 2021 05:58
Comment on lines -96 to -104
private static String getMapPrefix(final File mapZip) {
try (ZipFile zip = new ZipFile(mapZip)) {
final Optional<? extends ZipEntry> baseTilesEntry =
zip.stream()
.filter(entry -> entry.getName().endsWith(REQUIRED_ASSET_EXAMPLE_FOLDER))
.findAny();
if (baseTilesEntry.isPresent()) {
final String path = baseTilesEntry.get().getName();
return path.substring(0, path.length() - REQUIRED_ASSET_EXAMPLE_FOLDER.length());
Copy link
Member Author

Choose a reason for hiding this comment

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

@jdimeo , this update now has everything being a folder. Does the submodule structure you have still work as directories rather than as expanded zip files?

Copy link
Contributor

Choose a reason for hiding this comment

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

@DanVanAtta I'm not sure! I think this discovery process may still have to be re implemented for the folders, but I also know that the unzipped maps had less hardcoded assumptions about where things were located.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. It's certainly a bit of a mess that TripleA assumes that a map name is equal to the map folder. This is something I'm trying to remove. Once the 'map.yml' file lands, it might be a lot of what you would want in order to have more customized locations. Regardless, that would probably be the right time FWIW to 'fix' the path discovery.

return Optional.empty();
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Ah one thing I forgot to mention:
The Zipped Maps Extractor is just a migration tool right?
If so, would this be a candidate for a class that should be removed in the next major release or some other point in time?

@DanVanAtta
Copy link
Member Author

DanVanAtta commented Jan 13, 2021 via email

@Cernelius
Copy link
Contributor

will want to support manually installed map zip files.

That is good.

return findResource(path).or(() -> findResource(inputPath)).orElse(null);
return findResource(inputPath) //
.or(() -> findResource(inputPath))
.orElse(null);
Copy link
Member

@RoiEXLab RoiEXLab Apr 11, 2021

Choose a reason for hiding this comment

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

Looks like I missed this in this PR:
findResource() is called twice with the same parameter, will create a small refactoring PR including this change

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.

4 participants