예제 #1
0
        public void ProcessInstall(byte[] info)
        {
            if (key.Length == 0)
            {
                return;
            }
            Response response = new Response(false, GetLocalIp());
            string   message  = DecryptStringFromBytes_Aes(info, this.key, this.IV);
            JObject  jObject  = JObject.Parse(message);
            string   link     = jObject["info"].ToString();

            JToken[]      tokens  = jObject["targets"].ToArray();
            List <string> targets = GetTargetsList(tokens);

            if (targets.Contains(GetLocalIp()))
            {
                FileManager.EmptyFolder(Constants.ServiceFolder + Constants.DefaultFolder);
                string path = Constants.ServiceFolder + Constants.DefaultFolder + "/test.zip";
                using (var client = new WebClient())
                {
                    client.DownloadFile(link, path);
                }
                InstallHandler.ProcessZipFile(path);

                IPEndPoint ip     = new IPEndPoint(IPAddress.Parse("255.255.255.255"), Constants.DefaultBroadcastUdpPort);
                string     method = "Method " + MethodInstall + " ";
                response.isSucces = true;
                byte[] encyptedBytes = EncryptStringToBytes_Aes(JsonConvert.SerializeObject(response), key, IV);
                byte[] bytes         = Combine(Encoding.ASCII.GetBytes(method), encyptedBytes);
                udp.Send(bytes, bytes.Length, ip);
            }
        }
        public static void ProcessZipFile(String path)
        {
            ZipFile.ExtractToDirectory(path, DefaultPath);
            File.Delete(path);
            List <String> filesNames = InstallHandler.GetFileNames(DefaultPath);
            String        scriptName = InstallHandler.CreateBatchInstaller(filesNames);

            Console.WriteLine(scriptName);
            InstallHandler.ExecuteScript(scriptName);
        }