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;
|
Width = dims.X; Height = dims.Y; Length = dims.Z;
|
||||||
BlockDBEntries = BlockDBFile.CountEntries(name);
|
BlockDBEntries = BlockDBFile.CountEntries(name);
|
||||||
|
|
||||||
path = LevelInfo.FindPropertiesFile(name);
|
path = LevelInfo.PropertiesPath(name);
|
||||||
LevelConfig cfg = new LevelConfig();
|
LevelConfig cfg = new LevelConfig();
|
||||||
cfg.EdgeLevel = Height / 2; cfg.CloudsHeight = Height + 2;
|
cfg.EdgeLevel = Height / 2; cfg.CloudsHeight = Height + 2;
|
||||||
LevelConfig.Load(path, cfg);
|
LevelConfig.Load(path, cfg);
|
||||||
|
@ -30,18 +30,15 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
string[] files = LevelInfo.AllMapFiles();
|
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): ");
|
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);
|
"Worlds", "maps", message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string FormatMap(Player p, string map) {
|
static string FormatMap(Player p, string file) {
|
||||||
LevelPermission visitP, buildP;
|
LevelPermission visitP, buildP;
|
||||||
bool loadOnGoto;
|
bool loadOnGoto;
|
||||||
|
string map = Path.GetFileNameWithoutExtension(file);
|
||||||
RetrieveProps(map, out visitP, out buildP, out loadOnGoto);
|
RetrieveProps(map, out visitP, out buildP, out loadOnGoto);
|
||||||
|
|
||||||
LevelPermission maxPerm = visitP;
|
LevelPermission maxPerm = visitP;
|
||||||
@ -57,10 +54,9 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
build = LevelPermission.Guest;
|
build = LevelPermission.Guest;
|
||||||
loadOnGoto = true;
|
loadOnGoto = true;
|
||||||
|
|
||||||
string file = LevelInfo.FindPropertiesFile(level);
|
string propsPath = LevelInfo.PropertiesPath(level);
|
||||||
if (file == null) return;
|
|
||||||
SearchArgs args = new SearchArgs();
|
SearchArgs args = new SearchArgs();
|
||||||
PropertiesFile.Read(file, ref args, ProcessLine);
|
if (!PropertiesFile.Read(propsPath, ref args, ProcessLine)) return;
|
||||||
|
|
||||||
visit = Group.ParsePermOrName(args.Visit, visit);
|
visit = Group.ParsePermOrName(args.Visit, visit);
|
||||||
build = Group.ParsePermOrName(args.Build, build);
|
build = Group.ParsePermOrName(args.Build, build);
|
||||||
|
@ -71,9 +71,9 @@ namespace MCGalaxy.Commands.World {
|
|||||||
Level lvl = LevelInfo.FindExact(map);
|
Level lvl = LevelInfo.FindExact(map);
|
||||||
if (lvl != null) return lvl.Config;
|
if (lvl != null) return lvl.Config;
|
||||||
|
|
||||||
string propsPath = LevelInfo.FindPropertiesFile(map);
|
string propsPath = LevelInfo.PropertiesPath(map);
|
||||||
LevelConfig cfg = new LevelConfig();
|
LevelConfig cfg = new LevelConfig();
|
||||||
if (propsPath != null) LevelConfig.Load(propsPath, cfg);
|
LevelConfig.Load(propsPath, cfg);
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,8 +221,8 @@ namespace MCGalaxy {
|
|||||||
if (lvl.IsMuseum) return; // museums do not save properties
|
if (lvl.IsMuseum) return; // museums do not save properties
|
||||||
|
|
||||||
lock (lvl.savePropsLock) {
|
lock (lvl.savePropsLock) {
|
||||||
string path = LevelInfo.PropertiesPath(lvl.MapName);
|
string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
|
||||||
LevelConfig.Save(path, lvl.Config, lvl.name);
|
LevelConfig.Save(propsPath, lvl.Config, lvl.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,9 +363,10 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
public static void LoadMetadata(Level lvl) {
|
public static void LoadMetadata(Level lvl) {
|
||||||
try {
|
try {
|
||||||
string propsPath = LevelInfo.FindPropertiesFile(lvl.MapName);
|
string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
|
||||||
if (propsPath != null) {
|
bool propsExisted = LevelConfig.Load(propsPath, lvl.Config);
|
||||||
LevelConfig.Load(propsPath, lvl.Config);
|
|
||||||
|
if (propsExisted) {
|
||||||
lvl.setPhysics(lvl.Config.Physics);
|
lvl.setPhysics(lvl.Config.Physics);
|
||||||
} else {
|
} else {
|
||||||
Logger.Log(LogType.ConsoleMessage, ".properties file for level {0} was not found.", lvl.MapName);
|
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) {
|
public static bool Load(string path, LevelConfig config) {
|
||||||
PropertiesFile.Read(path, ref config, LineProcessor);
|
return PropertiesFile.Read(path, ref config, LineProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LineProcessor(string key, string value, ref LevelConfig config) {
|
static void LineProcessor(string key, string value, ref LevelConfig config) {
|
||||||
|
@ -88,21 +88,15 @@ namespace MCGalaxy {
|
|||||||
public static string PropertiesPath(string name) {
|
public static string PropertiesPath(string name) {
|
||||||
return "levels/level properties/" + name + ".properties";
|
return "levels/level properties/" + name + ".properties";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
public static string FindOfflineProperty(string name, string propKey) {
|
||||||
string file = FindPropertiesFile(name);
|
string path = PropertiesPath(name);
|
||||||
if (file == null) return null;
|
if (!File.Exists(path)) return null;
|
||||||
|
|
||||||
string[] lines = null;
|
string[] lines = null;
|
||||||
try {
|
try {
|
||||||
lines = File.ReadAllLines(file);
|
lines = File.ReadAllLines(path);
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool LoadOfflineLevel(Player p, string name) {
|
static bool LoadOfflineLevel(Player p, string name) {
|
||||||
string propsPath = LevelInfo.FindPropertiesFile(name);
|
string propsPath = LevelInfo.PropertiesPath(name);
|
||||||
LevelConfig cfg = new LevelConfig();
|
LevelConfig cfg = new LevelConfig();
|
||||||
LevelConfig.Load(propsPath, cfg);
|
LevelConfig.Load(propsPath, cfg);
|
||||||
|
|
||||||
|
@ -116,10 +116,11 @@ namespace MCGalaxy.Tasks {
|
|||||||
|
|
||||||
static void Combine(string envFile) {
|
static void Combine(string envFile) {
|
||||||
string name = Path.GetFileNameWithoutExtension(envFile);
|
string name = Path.GetFileNameWithoutExtension(envFile);
|
||||||
string propFile = LevelInfo.FindPropertiesFile(name);
|
string propsPath = LevelInfo.PropertiesPath(name);
|
||||||
|
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
if (propFile != null) {
|
if (File.Exists(propsPath)) {
|
||||||
lines = Utils.ReadAllLinesList(propFile);
|
lines = Utils.ReadAllLinesList(propsPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamReader r = new StreamReader(envFile)) {
|
using (StreamReader r = new StreamReader(envFile)) {
|
||||||
@ -128,8 +129,7 @@ namespace MCGalaxy.Tasks {
|
|||||||
lines.Add(line);
|
lines.Add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
propFile = LevelInfo.PropertiesPath(name);
|
File.WriteAllLines(propsPath, lines.ToArray());
|
||||||
File.WriteAllLines(propFile, lines.ToArray());
|
|
||||||
File.Delete(envFile);
|
File.Delete(envFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user