reverting pull request #46
Add support for snapshots when -mcpath is a network path (reverted from commitmaster4f78fbc24c
) refactorings (reverted from commit65adafa2f5
)
parent
8f67852eda
commit
154d19597a
|
@ -1,23 +0,0 @@
|
|||
package amidst.mojangapi.file;
|
||||
|
||||
import amidst.documentation.Immutable;
|
||||
|
||||
@Immutable
|
||||
public enum NetworkPathUtils {
|
||||
;
|
||||
|
||||
/*-
|
||||
* UNC path: \\server\share\foo
|
||||
* Absolute path: C:\foo
|
||||
* Relative path: foo
|
||||
* Directory_relative path: \foo
|
||||
* Drive_relative path: C:foo
|
||||
*/
|
||||
/**
|
||||
* @return true if the root directory is a UNC path (Uniform Naming
|
||||
* Convention, sometimes called a "network path")
|
||||
*/
|
||||
public static boolean isUNC(String path) {
|
||||
return path.startsWith("\\\\");
|
||||
}
|
||||
}
|
|
@ -8,9 +8,7 @@ import java.util.List;
|
|||
import amidst.documentation.GsonConstructor;
|
||||
import amidst.documentation.Immutable;
|
||||
import amidst.documentation.NotNull;
|
||||
import amidst.logging.Log;
|
||||
import amidst.mojangapi.MojangApi;
|
||||
import amidst.mojangapi.file.NetworkPathUtils;
|
||||
import amidst.mojangapi.file.directory.ProfileDirectory;
|
||||
import amidst.mojangapi.file.directory.VersionDirectory;
|
||||
import amidst.mojangapi.file.json.ReleaseType;
|
||||
|
@ -54,61 +52,21 @@ public class LauncherProfileJson {
|
|||
@NotNull
|
||||
public ProfileDirectory createValidProfileDirectory(MojangApi mojangApi)
|
||||
throws FileNotFoundException {
|
||||
File root = mojangApi.getDotMinecraftDirectory().getRoot();
|
||||
if (gameDir != null) {
|
||||
ProfileDirectory result = new ProfileDirectory(new File(gameDir));
|
||||
if (!result.isValid() && isSpecialCaseNetworkPath(root.getPath())) {
|
||||
result = createProfileDirectoryWithUNCPath(root.getPath());
|
||||
}
|
||||
if (result.isValid()) {
|
||||
return result;
|
||||
} else {
|
||||
throw new FileNotFoundException(
|
||||
"cannot find valid profile directory for launcher profile '"
|
||||
+ name + "': " + result.getRoot());
|
||||
+ name + "': " + gameDir);
|
||||
}
|
||||
} else {
|
||||
return new ProfileDirectory(root);
|
||||
return new ProfileDirectory(mojangApi.getDotMinecraftDirectory()
|
||||
.getRoot());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'network path' passed to the DotMinecraftDirectory allows for the
|
||||
* possibility that the DotMinecraftDirectory is located on a different
|
||||
* machine. Meanwhile, the gameDir from launcher_profile.json is a local
|
||||
* path for the computer the DotMinecraftDirectory is located on.
|
||||
*
|
||||
* When we tried to access the gameDir we found it didn't exist - which we
|
||||
* expect to happen if the gameDir holds a local path for a different
|
||||
* computer.
|
||||
*
|
||||
* As far as I can tell, there's no nice way in cross-platform Java to
|
||||
* resolve a network path into a server's local path, which would be the
|
||||
* first step in re-building a network path to access a remote gameDir, so
|
||||
* instead I'm only handling a common and known case...
|
||||
*
|
||||
* By default, across all platforms, normal profiles are kept in the
|
||||
* .minecraft directory, while snapshot profiles are now kept separate in
|
||||
* the .minecraft_snapshots directory. So if gameRoot is a network path to
|
||||
* the .minecraft directory, and launcher_profile.json specifies a local
|
||||
* path that ends in .minecraft_snapshots, then there's a damn good chance
|
||||
* it can be accessed via the same network path as the .minecraft directory.
|
||||
*/
|
||||
private boolean isSpecialCaseNetworkPath(String gameRoot) {
|
||||
return NetworkPathUtils.isUNC(gameRoot)
|
||||
&& gameRoot.endsWith(".minecraft")
|
||||
&& !NetworkPathUtils.isUNC(gameDir)
|
||||
&& gameDir.endsWith(".minecraft_snapshots");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ProfileDirectory createProfileDirectoryWithUNCPath(String gameRoot) {
|
||||
String uncGameDir = gameRoot + "_snapshots";
|
||||
Log.i("Profile directory for " + name
|
||||
+ " wasn't found, attempting a UNC path: " + uncGameDir);
|
||||
return new ProfileDirectory(new File(uncGameDir));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VersionDirectory createValidVersionDirectory(MojangApi mojangApi)
|
||||
throws FileNotFoundException {
|
||||
|
|
Loading…
Reference in New Issue