本文整理汇总了C#中IFolder.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# IFolder.Exists方法的具体用法?C# IFolder.Exists怎么用?C# IFolder.Exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFolder
的用法示例。
在下文中一共展示了IFolder.Exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Map
// Support upgrading format 5 maps to a more
// recent version by defining upgradeForMod.
public Map(string path, string upgradeForMod)
{
Path = path;
Container = GlobalFileSystem.OpenPackage(path, null, int.MaxValue);
AssertExists("map.yaml");
AssertExists("map.bin");
var yaml = new MiniYaml(null, MiniYaml.FromStream(Container.GetContent("map.yaml")));
FieldLoader.Load(this, yaml);
// Support for formats 1-3 dropped 2011-02-11.
// Use release-20110207 to convert older maps to format 4
// Use release-20110511 to convert older maps to format 5
if (MapFormat < 5)
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
// Format 5 -> 6 enforces the use of RequiresMod
if (MapFormat == 5)
{
if (upgradeForMod == null)
throw new InvalidDataException("Map format {0} is not supported, but can be upgraded.\n File: {1}".F(MapFormat, path));
Console.WriteLine("Upgrading {0} from Format 5 to Format 6", path);
// TODO: This isn't very nice, but there is no other consistent way
// of finding the mod early during the engine initialization.
RequiresMod = upgradeForMod;
}
var nd = yaml.ToDictionary();
// Load players
foreach (var my in nd["Players"].ToDictionary().Values)
{
var player = new PlayerReference(my);
Players.Add(player.Name, player);
}
Actors = Exts.Lazy(() =>
{
var ret = new Dictionary<string, ActorReference>();
foreach (var kv in nd["Actors"].ToDictionary())
ret.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.ToDictionary()));
return ret;
});
// Smudges
Smudges = Exts.Lazy(() =>
{
var ret = new List<SmudgeReference>();
foreach (var name in nd["Smudges"].ToDictionary().Keys)
{
var vals = name.Split(' ');
var loc = vals[1].Split(',');
ret.Add(new SmudgeReference(vals[0], new int2(
Exts.ParseIntegerInvariant(loc[0]),
Exts.ParseIntegerInvariant(loc[1])),
Exts.ParseIntegerInvariant(vals[2])));
}
return ret;
});
RuleDefinitions = MiniYaml.NodesOrEmpty(yaml, "Rules");
SequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Sequences");
VoxelSequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "VoxelSequences");
WeaponDefinitions = MiniYaml.NodesOrEmpty(yaml, "Weapons");
VoiceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Voices");
NotificationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Notifications");
TranslationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Translations");
MapTiles = Exts.Lazy(() => LoadMapTiles());
MapResources = Exts.Lazy(() => LoadResourceTiles());
TileShape = Game.modData.Manifest.TileShape;
// The Uid is calculated from the data on-disk, so
// format changes must be flushed to disk.
// TODO: this isn't very nice
if (MapFormat < 6)
Save(path);
Uid = ComputeHash();
if (Container.Exists("map.png"))
CustomPreview = new Bitmap(Container.GetContent("map.png"));
PostInit();
}
示例2: Map
// The standard constructor for most purposes
public Map(string path)
{
Path = path;
Container = GlobalFileSystem.OpenPackage(path, null, int.MaxValue);
AssertExists("map.yaml");
AssertExists("map.bin");
var yaml = new MiniYaml(null, MiniYaml.FromStream(Container.GetContent("map.yaml"), path));
FieldLoader.Load(this, yaml);
// Support for formats 1-3 dropped 2011-02-11.
// Use release-20110207 to convert older maps to format 4
// Use release-20110511 to convert older maps to format 5
// Use release-20141029 to convert older maps to format 6
if (MapFormat < 6)
throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));
var nd = yaml.ToDictionary();
// Format 6 -> 7 combined the Selectable and UseAsShellmap flags into the Class enum
if (MapFormat < 7)
{
MiniYaml useAsShellmap;
if (nd.TryGetValue("UseAsShellmap", out useAsShellmap) && bool.Parse(useAsShellmap.Value))
Visibility = MapVisibility.Shellmap;
else if (Type == "Mission" || Type == "Campaign")
Visibility = MapVisibility.MissionSelector;
}
SpawnPoints = Exts.Lazy(() =>
{
var spawns = new List<CPos>();
foreach (var kv in ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
{
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
}
return spawns.ToArray();
});
RuleDefinitions = MiniYaml.NodesOrEmpty(yaml, "Rules");
SequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Sequences");
VoxelSequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "VoxelSequences");
WeaponDefinitions = MiniYaml.NodesOrEmpty(yaml, "Weapons");
VoiceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Voices");
NotificationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Notifications");
TranslationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Translations");
PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");
ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
SmudgeDefinitions = MiniYaml.NodesOrEmpty(yaml, "Smudges");
MapTiles = Exts.Lazy(LoadMapTiles);
MapResources = Exts.Lazy(LoadResourceTiles);
MapHeight = Exts.Lazy(LoadMapHeight);
TileShape = Game.ModData.Manifest.TileShape;
SubCellOffsets = Game.ModData.Manifest.SubCellOffsets;
LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
DefaultSubCell = (SubCell)Game.ModData.Manifest.SubCellDefaultIndex;
if (Container.Exists("map.png"))
using (var dataStream = Container.GetContent("map.png"))
CustomPreview = new Bitmap(dataStream);
PostInit();
// The Uid is calculated from the data on-disk, so
// format changes must be flushed to disk.
// TODO: this isn't very nice
if (MapFormat < 7)
Save(path);
Uid = ComputeHash();
}
示例3: Compare
public static IFolderComparisonReport Compare(this IFolder folder1, IFolder folder2, ReportOption reportOption = ReportOption.EqualOnly)
{
#region Null & Not Exists folders cases
if (folder1 == null)
{
if (folder2 == null || !folder2.Exists())
return new FolderComparisonReport(equal: true);
return new FolderComparisonReport(equal: false);
}
if (folder2 == null)
{
if (!folder1.Exists())
return new FolderComparisonReport(equal: true);
return new FolderComparisonReport(equal: false);
}
if (!folder1.Exists() && !folder2.Exists())
return new FolderComparisonReport(equal: true);
if (!folder1.Exists() && folder2.Exists())
return new FolderComparisonReport(equal: false);
if (folder1.Exists() && !folder2.Exists())
return new FolderComparisonReport(equal: false);
#endregion
#region Files comparison
string[] entries1 = Directory.GetFileSystemEntries(folder1.Folder);
string[] entries2 = Directory.GetFileSystemEntries(folder2.Folder);
if (entries1.Length == 0 && entries2.Length == 0)
return new FolderComparisonReport(equal: true);
switch (reportOption)
{
case ReportOption.EqualOnly:
if (entries1.Length != entries2.Length)
return new FolderComparisonReport(equal: false);
break;
}
string[] files1 = Array.ConvertAll(Directory.GetFiles(folder1.Folder), fileName => Path.GetFileName(fileName).ToLower());
string[] files2 = Array.ConvertAll(Directory.GetFiles(folder2.Folder), fileName => Path.GetFileName(fileName).ToLower());
var uniqInFolder1 = new List<string>();
var uniqInFolder2 = new List<string>();
switch (reportOption)
{
case ReportOption.EqualOnly:
bool foundAllFilesFromList1InList2 = Found(files1, files2);
if (!foundAllFilesFromList1InList2)
return new FolderComparisonReport(equal: false);
bool foundAllFilesFromList2InList1 = Found(files2, files1);
if (!foundAllFilesFromList2InList1)
return new FolderComparisonReport(equal: false);
break;
case ReportOption.CollectDifferentFiles:
FoundUniq(files1, files2, uniqInFolder1, uniqInFolder2);
break;
default:
throw new NotImplementedException(String.Format("reportOption {0} not implemented", reportOption));
}
#endregion
#region Directory comparison
string[] directories1 = Array.ConvertAll(Directory.GetDirectories(folder1.Folder), folderName => Path.GetFileName(folderName).ToLower());
string[] directories2 = Array.ConvertAll(Directory.GetDirectories(folder2.Folder), folderName => Path.GetFileName(folderName).ToLower());
switch (reportOption)
{
case ReportOption.EqualOnly:
bool foundAllDirectoriesFromList1InList2 = Found(directories1, directories2);
if (!foundAllDirectoriesFromList1InList2)
return new FolderComparisonReport(equal: false);
bool foundAllDirectoriesFromList2InList1 = Found(directories2, directories1);
if (!foundAllDirectoriesFromList2InList1)
return new FolderComparisonReport(equal: false);
break;
case ReportOption.CollectDifferentFiles:
FoundUniq(directories1, directories2, uniqInFolder1, uniqInFolder2);
break;
default:
throw new NotImplementedException(String.Format("reportOption {0} not implemented", reportOption));
}
foreach (string subFolder in directories1)
{
IFolder subFolder1 = new DataFolder(Path.Combine(folder1.Folder, subFolder));
IFolder subFolder2 = new DataFolder(Path.Combine(folder2.Folder, subFolder));
IFolderComparisonReport comparisonReport = subFolder1.Compare(subFolder2, reportOption);
switch (reportOption)
{
case ReportOption.EqualOnly:
if (!comparisonReport.Equal)
return new FolderComparisonReport(equal: false);
break;
case ReportOption.CollectDifferentFiles:
uniqInFolder1.AddRange(comparisonReport.Folder1Files.ConvertAll(fileName => subFolder + @"\" + fileName));
//.........这里部分代码省略.........