Пример #1
0
        private void CreateDirectoryIfNotExists()
        {
            string directoryName = string.Empty;

            try
            {
                directoryName = Path.GetDirectoryName(filePath);
            }
            catch (IOException e)
            {
                Console.WriteLine($"Failed retrieving the directory from the supplied path! {e}");
            }

            if (!Directory.Exists(directoryName))
            {
                Console.WriteLine($"The directory {Path.GetDirectoryName(filePath)} doesn't exist! Attempting to create the directory");
                try
                {
                    FileCreator.CreateDirectory(filePath);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Attempt failed! {e}");
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Creates a new <see cref="Datapack"/> with the given parameters. Inherite from this constructor.
 /// </summary>
 /// <param name="path">The path to the folder to create this datapack in</param>
 /// <param name="packName">The datapack's name</param>
 /// <param name="description">The datapack's description</param>
 /// <param name="packFormat">The datapack's format</param>
 /// <param name="fileCreator">Class for creating files and directories</param>
 /// <param name="_">Unused parameter used for specifing you want to use this constructor</param>
 /// <param name="settings">Datapack settings</param>
 protected Datapack(string path, string packName, string description, int packFormat, IFileCreator fileCreator, IDatapackSetting[]?settings, bool _) : base(path, packName, fileCreator, settings)
 {
     FileCreator.CreateDirectory(Path + "/" + Name);
     using TextWriter metaWriter = FileCreator.CreateWriter(Path + "/" + Name + "/pack.mcmeta");
     metaWriter.Write("{\"pack\":{\"pack_format\":" + packFormat + ",\"description\":\"" + description + "\"}}");
 }