示例#1
0
        public override void Run(List <Variable> variableList)
        {
            var fileMaker = new NgFileMaker();

            Console.Write($@"Activating {ListFileCopy.Count} File ... ");
            foreach (var file in ListFileCopy)
            {
                var FileInfoSource      = file.FileInfoSource;
                var FileInfoDestination = file.FileInfoDestination;

                foreach (var variable in variableList)
                {
                    FileInfoSource      = FileInfoSource.Replace("@(" + variable.Name + ")", variable.Value);
                    FileInfoDestination = FileInfoDestination.Replace("@(" + variable.Name + ")", variable.Value);
                }

                var fsource = Environment.ExpandEnvironmentVariables(FileInfoSource);
                var fdest   = Environment.ExpandEnvironmentVariables(FileInfoDestination);

                var from = new FileInfo(fsource);
                var to   = new FileInfo(fdest);

                fileMaker.CopyFile(from, to);
            }
            Console.WriteLine("Done");
        }
示例#2
0
        public override void Run(List <Variable> variableList)
        {
            Console.Write($"Lockdown {ListHost.Count} host ... ");
            var fileMaker = new NgFileMaker();

            var path = Environment.ExpandEnvironmentVariables($@"%WINDIR%\system32\drivers\etc\hosts");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                path = "/etc/hosts";
            }

            fileMaker.SetAttributeFile(new FileInfo(path), FileAttributes.Normal);

            var hostText = fileMaker.ReadFromFile(path);
            var hostLine = hostText.Split(Environment.NewLine);

            var validHost = new List <String>();

            foreach (var host in ListHost)
            {
                var exist = false;
                foreach (var line in hostLine)
                {
                    if (line.ToLower().Contains(host.ToLower()))
                    {
                        if (!line.ToLower().Contains("#"))
                        {
                            exist = true;
                            break;
                        }
                    }
                }

                if (!exist)
                {
                    if (validHost.Where(x => x.ToLower() == host.ToLower()).Count() == 0)
                    {
                        validHost.Add(host);
                    }
                }
            }

            var newHost = new StringBuilder();

            newHost.AppendLine(hostText);

            foreach (var h in validHost)
            {
                newHost.AppendLine($"127.0.0.1 {h}");
            }

            fileMaker.WriteToFile(path, newHost.ToString());
            fileMaker.SetAttributeFile(new FileInfo(path), FileAttributes.ReadOnly);

            Console.WriteLine("Done");
        }
示例#3
0
        public override void Run(List <Variable> variableList)
        {
            Console.Write("Extracting app ... ");
            foreach (var variable in variableList)
            {
                FilePath      = FilePath.Replace("@(" + variable.Name + ")", variable.Value);
                ExtractFolder = ExtractFolder.Replace("@(" + variable.Name + ")", variable.Value);
            }

            FilePath      = Environment.ExpandEnvironmentVariables(FilePath);
            ExtractFolder = Environment.ExpandEnvironmentVariables(ExtractFolder);

            var fileMaker = new NgFileMaker();

            fileMaker.ExtractZip(new DirectoryInfo(ExtractFolder), new FileInfo(FilePath));
            Console.WriteLine("Done");
        }
        public override void Run(List <Variable> variableList)
        {
            var fileMaker = new NgFileMaker();

            var app = AppName.Replace(@"\", @"").Replace(@".app", @"");

            Console.Write($@"Install app {app} ... ");

            foreach (var variable in variableList)
            {
                AppName          = AppName.Replace("@(" + variable.Name + ")", variable.Value);
                FileName         = FileName.Replace("@(" + variable.Name + ")", variable.Value);
                WorkingDirectory = WorkingDirectory.Replace("@(" + variable.Name + ")", variable.Value);
            }

            FileName         = Environment.ExpandEnvironmentVariables(FileName);
            WorkingDirectory = Environment.ExpandEnvironmentVariables(WorkingDirectory);


            var appUninstallLoc = new System.IO.DirectoryInfo($@"/Applications/{AppName}");

            fileMaker.DeleteFolder(appUninstallLoc);


            var process = new Process();

            process.StartInfo.WorkingDirectory = WorkingDirectory;
            process.StartInfo.FileName         = @$ "/bin/bash";
            process.StartInfo.Arguments        = $@"-c ""mv {FileName} /Applications/{AppName.Replace(@" ", @"\ ")}""";
            process.StartInfo.Verb             = "runas";
            process.Start();
            process.WaitForExit();

            process = new Process();
            process.StartInfo.WorkingDirectory = WorkingDirectory;
            process.StartInfo.FileName         = @$ "/bin/bash";
            process.StartInfo.Arguments        = $@"-c ""xattr -cr /Applications/{AppName.Replace(@" ", @"\ ")}""";
            process.StartInfo.Verb             = "runas";
            process.Start();
            process.WaitForExit();

            Console.WriteLine("Done");
        }
示例#5
0
        public override void Run(List <Variable> variablesList)
        {
            foreach (var variable in variablesList)
            {
                FileInfoSource      = FileInfoSource.Replace("@(" + variable.Name + ")", variable.Value);
                FileInfoDestination = FileInfoDestination.Replace("@(" + variable.Name + ")", variable.Value);
            }

            Console.Write($"Activating File {new FileInfo(FileInfoSource).Name} ... ");

            var fileMaker = new NgFileMaker();
            var fsource   = Environment.ExpandEnvironmentVariables(FileInfoSource);
            var fdest     = Environment.ExpandEnvironmentVariables(FileInfoDestination);

            var from = new System.IO.FileInfo(fsource);
            var to   = new System.IO.FileInfo(fdest);

            fileMaker.CopyFile(from, to);
            Console.WriteLine($"Done");
        }
示例#6
0
        public override void Run(List <Variable> variableList)
        {
            Console.Write("Extracting app ... ");
            foreach (var variable in variableList)
            {
                FilePath      = FilePath.Replace("@(" + variable.Name + ")", variable.Value);
                ExtractFolder = ExtractFolder.Replace("@(" + variable.Name + ")", variable.Value);
            }

            FilePath      = Environment.ExpandEnvironmentVariables(FilePath);
            ExtractFolder = Environment.ExpandEnvironmentVariables(ExtractFolder);

            var fileMaker = new NgFileMaker();

            fileMaker.DeleteFolder(new DirectoryInfo(ExtractFolder));

            Process process = new Process();

            process.StartInfo.FileName  = @$ "/bin/bash";
            process.StartInfo.Arguments = $@"-c ""unzip -o -q {FilePath} -d {ExtractFolder}""";
            process.StartInfo.Verb      = "runas";
            process.Start();
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                throw new Exception($@"unzip app failed.");
            }

            process = new Process();
            process.StartInfo.FileName  = @$ "/bin/bash";
            process.StartInfo.Arguments = $@"-c ""chmod -R +r+w+x {ExtractFolder}""";
            process.StartInfo.Verb      = "runas";
            process.Start();
            process.WaitForExit();
            if (process.ExitCode != 0)
            {
                throw new Exception($@"unzip app failed.");
            }

            Console.WriteLine("Done");
        }
示例#7
0
        public override void Run(List <Variable> variableList)
        {
            var fileMaker = new NgFileMaker();

            Console.Write($@"Safe {ListFolderDelete.Count} Folder ... ");
            foreach (var folder in ListFolderDelete)
            {
                var path = folder.FolderPath;
                foreach (var variable in variableList)
                {
                    path = path.Replace("@(" + variable.Name + ")", variable.Value);
                }

                path = Environment.ExpandEnvironmentVariables(path);

                var fileInfo = new DirectoryInfo(path);

                var maxLoop = 2;
                for (int i = 0; i < maxLoop; i++)
                {
                    try
                    {
                        Thread.Sleep(10000);
                        fileMaker.DeleteFolder(fileInfo, folder.CheckFile);
                        break;
                    }
                    catch (Exception ex)
                    {
                        if (i == (maxLoop - 1))
                        {
                            throw;
                        }

                        Console.WriteLine(ex.Message);
                        Console.WriteLine("retrying...");
                    }
                }
            }
            Console.WriteLine("Done");
        }