Beispiel #1
0
        public void ExtractFile(string resource, string destinationPath)
        {
            var assembly     = typeof(TAssemblyOfType).GetTypeInfo().Assembly;
            var assemblyName = assembly.GetName().Name;

            var stream = assembly.GetManifestResourceStream($"{assemblyName}.{resource}");

            if (stream == null)
            {
                throw new InvalidOperationException($"Could not find {resource} inside {assemblyName}");
            }

            if (File.Exists(destinationPath))
            {
                File.Delete(destinationPath);
            }

            Directories.CreateIfNotExists(Path.GetDirectoryName(destinationPath));

            using (stream)
            {
                using (var fileStream = File.Create(destinationPath))
                {
                    stream.CopyTo(fileStream);
                }
            }
        }
Beispiel #2
0
        public void Template(string templateName, object input, params string[] to)
        {
            var template = GetTemplate(templateName);

            var shortDestination = Path.Combine(to);

            var destination = Path.Combine(Solution.RootDir, shortDestination);

            if (File.Exists(destination))
            {
                Console2.GreyLine($"\tSkip\t{Solution.RootDir.Relative(destination)}");
                return;
            }

            Console2.YellowLine($"\tCreate\t{Solution.RootDir.Relative(destination)}");

            var result = template.Render(new
            {
                Solution,
                MiruInfo.MiruVersion,
                input
            }, member => member.Name);

            Directories.CreateIfNotExists(Path.GetDirectoryName(destination));
            File.AppendAllText(destination, result);
        }
Beispiel #3
0
        /// <summary>
        /// Create a file with given content. File's directory will be created if it does not exist
        /// </summary>
        public static void Create(string file, string content)
        {
            Directories.CreateIfNotExists(Path.GetDirectoryName(file));

            using (var writer = File.CreateText(file))
            {
                writer.Write(content);
            }
        }
Beispiel #4
0
 public static void EnsureDirExist(this MiruPath miruPath) =>
 Directories.CreateIfNotExists(miruPath);