Exemplo n.º 1
0
        private void CleanCopyRename()
        {
            var src = new Enumerator(sourcePath);
            string oldname = Parameter.SourceSolutionName;
            string newname = Parameter.DestinationName;
            if (newname.ToLower().EndsWith(".zip"))
            {
                newname = newname.Substring(0, newname.Length - 4);
            }

            if (Directory.Exists(destinationPath))
            {
                throw new Exception("destination directory is exist.");
            }

            foreach (string d in src.Directories())
            {
                string np = src.RelativePath(d);
                if (Parameter.NeedRename)
                {
                    np = np.Replace(oldname, newname);
                }
                Directory.CreateDirectory(Path.Combine(destinationPath, np));
            }

            foreach (string f in src.Files())
            {
                string nf = src.RelativePath(f);
                if (Parameter.NeedRename)
                {
                    nf = nf.Replace(oldname, newname);
                }

                string fp = Path.Combine(destinationPath, nf);
                File.Copy(f, fp);

                if (Parameter.NeedRename)
                {
                    File.WriteAllLines(
                        fp,
                        File.ReadAllLines(fp).Select(l => l.Replace(oldname, newname)),
                        Encoding.UTF8
                        );
                }
            }
        }
Exemplo n.º 2
0
        private void Zip()
        {
            if (!Parameter.IsZipDestination) return;

            using (var zip = new ZipFile(destinationZip))
            {
                var src = new Enumerator(destinationPath);

                foreach (string file in src.Files())
                {
                    string p = Path.GetDirectoryName(file);
                    zip.AddFile(file, src.RelativePath(p));
                }

                zip.Save();
            }
        }