Esempio n. 1
0
        private static void checkFilesFolders(string folder)
        {
            if (isArma2)
            {
                //armaPath = regcheck.arma2RegCheck();
                armaPath = path("ArmA2");
            }
            else
            {
                //armaPath = Settings.Default.A3path;
                armaPath = path("ArmA3");
            }
            string relativePath = folder.Replace(armaPath, "");

            string[] files = downloader.webReadLines(url + relativePath.Replace(@"\\", "") + "/files.cfg");

            var info = new DirectoryInfo(folder);

            string[] dirs = downloader.webReadLines(url + relativePath + "\\dirs.cfg");

            foreach (DirectoryInfo dirInfo in info.GetDirectories())
            {
                bool exists = false;
                foreach (string dir in dirs)
                {
                    if (dir == dirInfo.Name)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    dirInfo.Delete(true);
                }
            }

            foreach (string dir in dirs)
            {
                var dirInfo = new DirectoryInfo(folder + "\\" + dir);
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }
                checkFilesFolders(dirInfo.FullName);
            }

            foreach (FileInfo file in info.GetFiles())
            {
                bool exists = false;
                foreach (string fileString in files)
                {
                    if (file.Name == fileString)
                    {
                        exists = true;
                    }
                }
                if (exists == false)
                {
                    file.Delete();
                }
            }
            var client = new WebClient();

            foreach (string file in files)
            {
                var fileInfo = new FileInfo(folder + "\\" + file);
                if (fileInfo.Exists)
                {
                    string hash           = RepoGenerator.md5Calc(fileInfo.FullName);
                    string downloadedHash = downloader.webRead(url + relativePath + "\\" + fileInfo.Name + ".hash");
                    if (hash != downloadedHash)
                    {
                        downloader.download(url + relativePath + "\\" + fileInfo.Name + ".7z", client);
                        Unzippy.extract(fileInfo.Name + ".7z", fileInfo.DirectoryName);
                        increment();
                        File.Delete(fileInfo.Name + ".7z");
                    }
                }
                else
                {
                    downloader.download(url + relativePath + "\\" + fileInfo.Name + ".7z", client);
                    Unzippy.extract(fileInfo.Name + ".7z", fileInfo.DirectoryName);
                    increment();
                    File.Delete(fileInfo.Name + ".7z");
                }
            }

            if (info.Name == "plugin")
            {
                //Now Create all of the directories
                foreach (string dirPath in Directory.GetDirectories(info.FullName, "*",
                                                                    SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins"));
                }

                //Copy all the files
                foreach (string newPath in Directory.GetFiles(info.FullName, "*.*", SearchOption.AllDirectories))
                {
                    if (!File.Exists(newPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins")))
                    {
                        try
                        {
                            File.Copy(newPath, newPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins"),
                                      true);
                            logIt.add("Copied ACRE plugin to TS3 folder");
                        }
                        catch (Exception e)
                        {
                            WindowManager.mainWindow.Worker.ReportProgress(-1, e.Message);
                            logIt.add("Failed to copy ACRE plugin to TS3 folder. Error Message: " + e.Message);
                        }
                    }
                    else
                    {
                        Process[] pro64 = Process.GetProcessesByName("ts3client_win64");
                        Process[] pro32 = Process.GetProcessesByName("ts3client_win32");

                        if (pro32.Length == 0 && pro64.Length == 0)
                        {
                            logIt.add("TS3 is not running");
                            File.Delete(newPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins"));
                            File.Copy(newPath, newPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins"));
                        }
                        else
                        {
                            logIt.add("TS3 is running");
                            if (UpdateManager.TFRalert == true)
                            {
                                MessageBox.Show("Teamspeak will now be closed to update the plugin files.", "Teamspeak will now close...", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            }
                            foreach (Process p in pro64)
                            {
                                p.Kill();
                            }

                            foreach (Process p in pro32)
                            {
                                p.Kill();
                            }

                            File.Delete(newPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins"));
                            File.Copy(newPath, newPath.Replace(info.FullName, Settings.Default.ts3Dir + "\\plugins"));
                        }
                    }
                }
            }

            if (info.Name == "userconfig")
            {
                string output = armaPath + "\\userconfig";
                Directory.CreateDirectory(output);

                foreach (string dirPath in Directory.GetDirectories(info.FullName, "*",
                                                                    SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace(info.FullName, output));
                }

                foreach (string newPath in Directory.GetFiles(info.FullName, "*.*",
                                                              SearchOption.AllDirectories))
                {
                    try
                    {
                        File.Copy(newPath, newPath.Replace(info.FullName, output), true);
                    }
                    catch (Exception e)
                    {
                        WindowManager.mainWindow.Worker.ReportProgress(-1, e.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        static private void checkFilesFolders(string folder)
        {
            string relativePath = folder.Replace(arma2Path, "");

            string[] files = downloader.webReadLines(url + relativePath + "/files.cfg");

            DirectoryInfo info = new DirectoryInfo(folder);

            string[] dirs = downloader.webReadLines(url + relativePath + "\\dirs.cfg");

            foreach (DirectoryInfo dirInfo in info.GetDirectories())
            {
                bool exists = false;
                foreach (string dir in dirs)
                {
                    if (dir == dirInfo.Name)
                    {
                        exists = true;
                    }
                }
                if (!exists)
                {
                    dirInfo.Delete(true);
                }
            }

            foreach (string dir in dirs)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(folder + "\\" + dir);
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }
                checkFilesFolders(dirInfo.FullName);
            }

            foreach (FileInfo file in info.GetFiles())
            {
                bool exists = false;
                foreach (string fileString in files)
                {
                    if (file.Name == fileString)
                    {
                        exists = true;
                    }
                }
                if (exists == false)
                {
                    file.Delete();
                }
            }
            WebClient client = new WebClient();

            foreach (string file in files)
            {
                FileInfo fileInfo = new FileInfo(folder + "\\" + file);
                if (fileInfo.Exists)
                {
                    string hash           = RepoGenerator.md5Calc(fileInfo.FullName);
                    string downloadedHash = downloader.webRead(url + relativePath + "\\" + fileInfo.Name + ".hash");
                    if (hash != downloadedHash)
                    {
                        downloader.download(url + relativePath + "\\" + fileInfo.Name + ".7z", client);
                        Unzippy.extract(fileInfo.Name + ".7z", fileInfo.DirectoryName);
                        increment();
                        File.Delete(fileInfo.Name + ".7z");
                    }
                }
                else
                {
                    downloader.download(url + relativePath + "\\" + fileInfo.Name + ".7z", client);
                    Unzippy.extract(fileInfo.Name + ".7z", fileInfo.DirectoryName);
                    increment();
                    File.Delete(fileInfo.Name + ".7z");
                }
            }

            if (info.Name == "plugin")
            {
                //Now Create all of the directories
                foreach (string dirPath in Directory.GetDirectories(info.FullName, "*",
                                                                    SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace(info.FullName, Properties.Settings.Default.ts3Dir + "\\plugins"));
                }

                //Copy all the files
                foreach (string newPath in Directory.GetFiles(info.FullName, "*.*", SearchOption.AllDirectories))
                {
                    if (!File.Exists(newPath.Replace(info.FullName, Properties.Settings.Default.ts3Dir + "\\plugins")))
                    {
                        try {
                            File.Copy(newPath, newPath.Replace(info.FullName, Properties.Settings.Default.ts3Dir + "\\plugins"), true);
                            logIt.addData("Copied ACRE plugin to TS3 folder");
                        } catch (Exception e) {
                            WindowManager.mainWindow.worker.ReportProgress(-1, e.Message);
                            logIt.addData("Failed to copy ACRE plugin to TS3 folder. Error Message: " + e.Message);
                        }
                    }
                }
            }

            if (info.Name == "userconfig")
            {
                string output = arma2Path + "\\userconfig";
                Directory.CreateDirectory(output);

                foreach (string dirPath in Directory.GetDirectories(info.FullName, "*",
                                                                    SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(dirPath.Replace(info.FullName, output));
                }

                foreach (string newPath in Directory.GetFiles(info.FullName, "*.*",
                                                              SearchOption.AllDirectories))
                {
                    try {
                        File.Copy(newPath, newPath.Replace(info.FullName, output), true);
                    } catch (Exception e) {
                        WindowManager.mainWindow.worker.ReportProgress(-1, e.Message);
                    }
                }
            }
        }