mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Eliminate some useless File.Exists calls
This commit is contained in:
parent
83e6172137
commit
89a8823981
@ -217,7 +217,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
Width = dims.X; Height = dims.Y; Length = dims.Z;
|
||||
BlockDBEntries = BlockDBFile.CountEntries(name);
|
||||
|
||||
path = LevelInfo.FindPropertiesFile(name);
|
||||
path = LevelInfo.PropertiesPath(name);
|
||||
LevelConfig cfg = new LevelConfig();
|
||||
cfg.EdgeLevel = Height / 2; cfg.CloudsHeight = Height + 2;
|
||||
LevelConfig.Load(path, cfg);
|
||||
|
@ -30,18 +30,15 @@ namespace MCGalaxy.Commands.Info {
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] files = LevelInfo.AllMapFiles();
|
||||
for (int i = 0; i < files.Length; i++) {
|
||||
files[i] = Path.GetFileNameWithoutExtension(files[i]);
|
||||
}
|
||||
|
||||
Player.Message(p, "Maps (&c[no] %Sif not visitable): ");
|
||||
MultiPageOutput.Output(p, files, (map) => FormatMap(p, map),
|
||||
MultiPageOutput.Output(p, files, (file) => FormatMap(p, file),
|
||||
"Worlds", "maps", message, false);
|
||||
}
|
||||
|
||||
static string FormatMap(Player p, string map) {
|
||||
static string FormatMap(Player p, string file) {
|
||||
LevelPermission visitP, buildP;
|
||||
bool loadOnGoto;
|
||||
string map = Path.GetFileNameWithoutExtension(file);
|
||||
RetrieveProps(map, out visitP, out buildP, out loadOnGoto);
|
||||
|
||||
LevelPermission maxPerm = visitP;
|
||||
@ -57,10 +54,9 @@ namespace MCGalaxy.Commands.Info {
|
||||
build = LevelPermission.Guest;
|
||||
loadOnGoto = true;
|
||||
|
||||
string file = LevelInfo.FindPropertiesFile(level);
|
||||
if (file == null) return;
|
||||
string propsPath = LevelInfo.PropertiesPath(level);
|
||||
SearchArgs args = new SearchArgs();
|
||||
PropertiesFile.Read(file, ref args, ProcessLine);
|
||||
if (!PropertiesFile.Read(propsPath, ref args, ProcessLine)) return;
|
||||
|
||||
visit = Group.ParsePermOrName(args.Visit, visit);
|
||||
build = Group.ParsePermOrName(args.Build, build);
|
||||
|
@ -71,9 +71,9 @@ namespace MCGalaxy.Commands.World {
|
||||
Level lvl = LevelInfo.FindExact(map);
|
||||
if (lvl != null) return lvl.Config;
|
||||
|
||||
string propsPath = LevelInfo.FindPropertiesFile(map);
|
||||
string propsPath = LevelInfo.PropertiesPath(map);
|
||||
LevelConfig cfg = new LevelConfig();
|
||||
if (propsPath != null) LevelConfig.Load(propsPath, cfg);
|
||||
LevelConfig.Load(propsPath, cfg);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
@ -221,8 +221,8 @@ namespace MCGalaxy {
|
||||
if (lvl.IsMuseum) return; // museums do not save properties
|
||||
|
||||
lock (lvl.savePropsLock) {
|
||||
string path = LevelInfo.PropertiesPath(lvl.MapName);
|
||||
LevelConfig.Save(path, lvl.Config, lvl.name);
|
||||
string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
|
||||
LevelConfig.Save(propsPath, lvl.Config, lvl.name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,9 +363,10 @@ namespace MCGalaxy {
|
||||
|
||||
public static void LoadMetadata(Level lvl) {
|
||||
try {
|
||||
string propsPath = LevelInfo.FindPropertiesFile(lvl.MapName);
|
||||
if (propsPath != null) {
|
||||
LevelConfig.Load(propsPath, lvl.Config);
|
||||
string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
|
||||
bool propsExisted = LevelConfig.Load(propsPath, lvl.Config);
|
||||
|
||||
if (propsExisted) {
|
||||
lvl.setPhysics(lvl.Config.Physics);
|
||||
} else {
|
||||
Logger.Log(LogType.ConsoleMessage, ".properties file for level {0} was not found.", lvl.MapName);
|
||||
|
@ -201,8 +201,8 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
public static void Load(string path, LevelConfig config) {
|
||||
PropertiesFile.Read(path, ref config, LineProcessor);
|
||||
public static bool Load(string path, LevelConfig config) {
|
||||
return PropertiesFile.Read(path, ref config, LineProcessor);
|
||||
}
|
||||
|
||||
static void LineProcessor(string key, string value, ref LevelConfig config) {
|
||||
|
@ -90,19 +90,13 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
public static string FindPropertiesFile(string name) {
|
||||
string file = "levels/level properties/" + name + ".properties";
|
||||
if (!File.Exists(file)) file = "levels/level properties/" + name;
|
||||
return File.Exists(file) ? file : null;
|
||||
}
|
||||
|
||||
public static string FindOfflineProperty(string name, string propKey) {
|
||||
string file = FindPropertiesFile(name);
|
||||
if (file == null) return null;
|
||||
string path = PropertiesPath(name);
|
||||
if (!File.Exists(path)) return null;
|
||||
|
||||
string[] lines = null;
|
||||
try {
|
||||
lines = File.ReadAllLines(file);
|
||||
lines = File.ReadAllLines(path);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
static bool LoadOfflineLevel(Player p, string name) {
|
||||
string propsPath = LevelInfo.FindPropertiesFile(name);
|
||||
string propsPath = LevelInfo.PropertiesPath(name);
|
||||
LevelConfig cfg = new LevelConfig();
|
||||
LevelConfig.Load(propsPath, cfg);
|
||||
|
||||
|
@ -116,10 +116,11 @@ namespace MCGalaxy.Tasks {
|
||||
|
||||
static void Combine(string envFile) {
|
||||
string name = Path.GetFileNameWithoutExtension(envFile);
|
||||
string propFile = LevelInfo.FindPropertiesFile(name);
|
||||
string propsPath = LevelInfo.PropertiesPath(name);
|
||||
|
||||
List<string> lines = new List<string>();
|
||||
if (propFile != null) {
|
||||
lines = Utils.ReadAllLinesList(propFile);
|
||||
if (File.Exists(propsPath)) {
|
||||
lines = Utils.ReadAllLinesList(propsPath);
|
||||
}
|
||||
|
||||
using (StreamReader r = new StreamReader(envFile)) {
|
||||
@ -128,8 +129,7 @@ namespace MCGalaxy.Tasks {
|
||||
lines.Add(line);
|
||||
}
|
||||
|
||||
propFile = LevelInfo.PropertiesPath(name);
|
||||
File.WriteAllLines(propFile, lines.ToArray());
|
||||
File.WriteAllLines(propsPath, lines.ToArray());
|
||||
File.Delete(envFile);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user