Esempio n. 1
0
        public static void GenRepo()
        {
            ArrayList quickRepoList = new ArrayList();

            //Get list of mods from server, pull the XML for each one
            Log.Info("building list of files");
            foreach (string modlist in remoteSettings.modsArray)
            {
                //Quick PBO list
                PBOList tempQuickRepo = new PBOList();
                tempQuickRepo.GeneratePBOListFromDir(modlist);
                quickRepoList.Add(tempQuickRepo);
            }
            ;

            //Add hashes to each quick repo
            Log.InfoStamp("hashing files stored locally");
            for (int i = 0; i < remoteSettings.modsArray.Length; i++)
            {
                Log.Info(remoteSettings.modsArray[i]);
                PBOList tempQuickRepo = (PBOList)quickRepoList[i];
                tempQuickRepo.AddHashesToList();
                tempQuickRepo.RemoveModFolderForServerRepo();
                quickRepoList.Add(tempQuickRepo);
            }
            ;

            Log.InfoStamp("saving xml");
            for (int i = 0; i < remoteSettings.modsArray.Length; i++)
            {
                Log.Info(remoteSettings.modsArray[i]);
                PBOList tempQuickRepo = (PBOList)quickRepoList[i];
                tempQuickRepo.DeleteXML(Path.Combine(LOCAL_FOLDER, (remoteSettings.modsArray[i] + ".xml")));
                tempQuickRepo.AddModPathToList();
                tempQuickRepo.WriteXMLToDisk(Path.Combine(LOCAL_FOLDER, (remoteSettings.modsArray[i] + ".xml")));
            }
            ;
        }
Esempio n. 2
0
        public static bool Sync(bool forceSync)
        {
            ArrayList remoteRepoList = new ArrayList();
            ArrayList localRepoList  = new ArrayList();
            ArrayList quickRepoList  = new ArrayList();

            //Get list of mods from server, pull the XML for each one
            Log.Info("building list of files");
            foreach (string modlist in remoteSettings.modsArray)
            {
                //For remote XMLs
                PBOList tempServerRepo = new PBOList();
                tempServerRepo = tempServerRepo.ReadFromDisk(Path.Combine(localSettings.server, (modlist + ".xml")));
                remoteRepoList.Add(tempServerRepo);

                //For local XMLs
                PBOList tempLocalRepo = new PBOList();
                tempLocalRepo = tempLocalRepo.ReadFromDisk(Path.Combine(LOCAL_FOLDER, (modlist + ".xml")));
                localRepoList.Add(tempLocalRepo);

                //Quick PBO list
                PBOList tempQuickRepo = new PBOList();
                tempQuickRepo.GeneratePBOListFromDir(modlist);
                quickRepoList.Add(tempQuickRepo);
            }
            ;

            //Check the server repo for mods, if the list is empty, something is wrong
            if (remoteRepoList.Count == 0)
            {
                Log.Info("something is wrong with the server files, the server may be down temporarily");
                return(true);
            }
            ;

            //Check the local mod directory, if it's blank throw error, recreate settings
            if (localSettings.modfolder == "")
            {
                Log.Info("the mod folder appears to be blank, removing");
                PBOList temp = new PBOList();
                temp.DeleteXML(LOCAL_SETTINGS);
                return(false);
            }
            ;

            //Check each quick repo against it's corresponding local repo
            bool      haveFilesChanged = false;
            ArrayList modsThatChanged  = new ArrayList();

            //Check quick vs local(xml) repo
            for (int i = 0; i < localRepoList.Count; i++)
            {
                PBOList tempLocalRepo = (PBOList)localRepoList[i];
                PBOList tempQuickRepo = (PBOList)quickRepoList[i];
                if (tempLocalRepo.HaveFileNamesChanged(tempQuickRepo) || forceSync)
                {
                    haveFilesChanged = true;
                    modsThatChanged.Add(true);
                }
                else
                {
                    modsThatChanged.Add(false);
                }
            }
            ;
            //Check quick vs remote repo
            for (int i = 0; i < localRepoList.Count; i++)
            {
                PBOList tempRemoteRepo = (PBOList)remoteRepoList[i];
                PBOList tempQuickRepo  = (PBOList)quickRepoList[i];
                if (tempRemoteRepo.HaveFileNamesChanged(tempQuickRepo) || forceSync)
                {
                    haveFilesChanged   = true;
                    modsThatChanged[i] = true; //modifies the value from the first check
                }
                ;
            }
            ;

            //Run checks, downloads, and deletions if files have changed
            if (haveFilesChanged || forceSync || remoteSettings.forceHash)
            {
                Log.Info("changes detected or checking has been forced");

                //Add hashes to each quick repo
                Log.InfoStamp("hashing files stored locally");
                for (int i = 0; i < remoteSettings.modsArray.Length; i++)
                {
                    //Only hash mod folders that have changed
                    if ((bool)modsThatChanged[i])
                    {
                        Log.Info(remoteSettings.modsArray[i]);
                        PBOList tempQuickRepo = (PBOList)quickRepoList[i];
                        tempQuickRepo.AddHashesToList();
                        quickRepoList.RemoveAt(i);
                        quickRepoList.Insert(i, tempQuickRepo);
                    }
                    ;
                }
                ;

                //Check each quick repo to each remote repo
                Log.InfoStamp("finding files to delete");
                ArrayList deleteRepoList = new ArrayList();
                for (int i = 0; i < remoteSettings.modsArray.Length; i++)
                {
                    if ((bool)modsThatChanged[i])
                    {
                        PBOList tempQuickRepo  = (PBOList)quickRepoList[i];
                        PBOList tempRemoteRepo = (PBOList)remoteRepoList[i];
                        deleteRepoList.Add(tempQuickRepo.GetDeleteList(tempRemoteRepo));
                    }
                }
                ;

                //Get number of files going to be downloaded
                int tempCountDelete = 0;
                foreach (PBOList tempDeleteRepo in deleteRepoList)
                {
                    tempCountDelete = tempCountDelete + tempDeleteRepo.Count;
                }

                if (tempCountDelete > 0)
                {
                    Log.Info(tempCountDelete + " files will be deleted");

                    //Delete
                    foreach (PBOList tempDeleteRepo in deleteRepoList)
                    {
                        tempDeleteRepo.DeleteFilesOnDisk();
                    }
                    Log.Info("files deleted");

                    //Check for empty folders to delete
                    Log.Info("deleting any empty folders");
                    foreach (string dir in remoteSettings.modsArray)
                    {
                        if (Directory.Exists(Path.Combine(localSettings.modfolder, dir)))
                        {
                            FileHandler.DeleteEmptyFolders(Path.Combine(localSettings.modfolder, dir));
                        }
                    }
                }
                else
                {
                    Log.Info("no files to delete");
                };

                //cycle list of pbo downloads
                Log.InfoStamp("finding files to download");
                ArrayList downloadRepoList = new ArrayList();
                for (int i = 0; i < remoteSettings.modsArray.Length; i++)
                {
                    if ((bool)modsThatChanged[i])
                    {
                        PBOList tempQuickRepo  = (PBOList)quickRepoList[i];
                        PBOList tempRemoteRepo = (PBOList)remoteRepoList[i];
                        downloadRepoList.Add(tempQuickRepo.GetDownloadList(tempRemoteRepo));
                    }
                }
                ;

                //Get number of files going to be downloaded
                int tempCountDownload = 0;
                foreach (PBOList tempDownloadRepo in downloadRepoList)
                {
                    tempCountDownload = +tempDownloadRepo.Count;
                }

                if (tempCountDownload > 0)
                {
                    Log.Info(tempCountDownload + " files will be downloaded");

                    //Download
                    foreach (PBOList tempDownloadRepo in downloadRepoList)
                    {
                        HTTP.DownloadList(tempDownloadRepo);
                    }
                    ;
                    Log.Info("files downloaded");
                }
                else
                {
                    Log.Info("no files to download");
                };

                //save to xml, add the repo from the server after adding back our modfolder
                Log.InfoStamp("saving xml");
                for (int i = 0; i < remoteSettings.modsArray.Length; i++)
                {
                    Log.Info(remoteSettings.modsArray[i]);
                    PBOList tempLocalRepo  = (PBOList)localRepoList[i];
                    PBOList tempRemoteRepo = (PBOList)remoteRepoList[i];
                    tempLocalRepo.Clear();
                    tempLocalRepo.DeleteXML(Path.Combine(LOCAL_FOLDER, (remoteSettings.modsArray[i] + ".xml")));
                    tempLocalRepo.AddModPathToList();
                    tempLocalRepo.AddRange(tempRemoteRepo);
                    tempLocalRepo.WriteXMLToDisk(Path.Combine(LOCAL_FOLDER, (remoteSettings.modsArray[i] + ".xml")));
                }
                ;

                //Mods changed
                Log.InfoStamp("checking files for consistency");
                return(false);
            }
            else
            {
                //Mods did not change
                Log.Info("all done, no changes detected");
                return(true);
            };
        }