private static void Cache_Result(string remote_path, string local_path, FILE_UPDATE_STATUS val) { string repo_url = Extract_Repository_URL_From_Github_URL(remote_path); string rSHA = Get_Repo_SHA(repo_url); // Check and see if the current repository hash matches the one we were tracking for this url. JSONNode node = Tracker[repo_url]; if (node == null) { Reset_Tracker_For_Repo(repo_url); } JSONClass repo = (JSONClass)node; string last_SHA = repo["sha"].Value; if (last_SHA == null || String.Compare(last_SHA, rSHA) != 0) { Reset_Tracker_For_Repo(repo_url); } // Get the hash for the file we're checking on. string cSHA = Util.Git_File_Sha1_Hash(local_path); repo[cSHA] = new JSONData((int)val); Tracker.Save(); }
private static FILE_UPDATE_STATUS?Get_Cached_Result(string remote_path, string local_path) { string repo_url = Extract_Repository_URL_From_Github_URL(remote_path); string rSHA = Get_Repo_SHA(repo_url); // Check and see if the current repository hash matches the one we were tracking for this url. JSONNode tval = Tracker[repo_url]; if (tval == null) { //Looks like we don't have a cached value for anything in this repo. // So let's create an instance for it and then return null. Reset_Tracker_For_Repo(repo_url); return(null); } JSONClass repo = (JSONClass)tval; string last_SHA = repo["sha"].Value; if (last_SHA == null) { // For some reason we don't have a value for the repo sha. so clear the repo data, set the hash and return null. Reset_Tracker_For_Repo(repo_url); return(null); } if (String.Compare(last_SHA, rSHA) != 0) { // Whelp looks like the repo has changed since we last started caching stuff. clear all of our, now old, data for it. Reset_Tracker_For_Repo(repo_url); return(null); } // Get the hash for the file we're checking on. string cSHA = Util.Git_File_Sha1_Hash(local_path); // See if we have a stored result for a file with this hash if (repo[cSHA] == null) { return(null); } // we do, return it! FILE_UPDATE_STATUS last = (FILE_UPDATE_STATUS)repo[cSHA].AsInt; return(last); }
/// <summary> /// Causes this plugin to check and see if it has any updates. /// </summary> public bool check_for_updates() { if (is_update_available) { return(true); } if (data == null) { SLog.Warn("{0} Plugin has no DATA structure!", this); return(false); } if (data.UPDATE_METHOD == null || !data.UPDATE_METHOD.Valid) { return(false); } _update_status = Updater.Get_Update_Status(data.UPDATE_METHOD.URL, FilePath); is_update_available = (_update_status == FILE_UPDATE_STATUS.OUT_OF_DATE); //PLog.Info("{0} update_status: {1}", this, Enum.GetName(typeof(FILE_UPDATE_STATUS), status)); return(is_update_available); }
private IEnumerator Check_For_Updates() { SLog.Info("[AutoUpdater] Checking for updates..."); List <UpdateFile> updates = new List <UpdateFile>(); // We should automatically keep ALL files within the repositorys "installer" directory insync! var iter = Git_Updater.Get_Repo_Folder_Files_Async("https://raw.github.com/dsisco11/SR_Plugin_Loader/master/", "/Installer/"); if (iter == null) { yield break; } while (iter.MoveNext()) { yield return(null); } if (iter.Current != null) { List <UpdateFile> list = (List <UpdateFile>)iter.Current; string exDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); foreach (UpdateFile file in list) { string FN = Path.GetFileName(file.FILE); string dir = exDir; if (String.Compare("SR_PluginLoader_Uninstaller.exe", FN) == 0) { dir = Path.GetFullPath(String.Concat(dir, "/../../")); } string local_path = Path.Combine(dir, FN); file.LOCAL_PATH = local_path; var it = Git_Updater.instance.Get_Update_Status_Async(file.FULLNAME, local_path); if (it == null) { continue; } while (it.MoveNext()) { yield return(null); } FILE_UPDATE_STATUS status = (FILE_UPDATE_STATUS)it.Current; //status = FILE_UPDATE_STATUS.OUT_OF_DATE;// DEBUG //PLog.Info("{0} | LOCAL_PATH: {1} | REMOTE_PATH: {2}", file.FULLNAME, local_path, file.URL); if (status == FILE_UPDATE_STATUS.OUT_OF_DATE) { updates.Add(file); } } } // If we have updates prompt the user to accept them. if (updates.Count > 0) { SLog.Info("[AutoUpdater] {0} Updates Available.", updates.Count); var updatesView = uiControl.Create <uiUpdatesAvailable>(); updatesView.onResult += (DialogResult res) => { if (res == DialogResult.OK) { // The user said OK so let's start downloading var updater = (new GameObject().AddComponent <PluginLoader_AutoUpdater>()); updater.Files = updatesView.Files; updater.updatesView = updatesView; return(true); } return(false); }; foreach (var f in updates) { updatesView.Add_File(f); } if (MainMenu.isReady) { updatesView.Show(); } else { SiscosHooks.Once(HOOK_ID.MainMenu_Loaded, () => { updatesView.Show(); }); } } else { SLog.Info("[AutoUpdater] No updates."); } yield return(null); yield break; }