private static void OpenUpdateFile() { CheckFileExist(); try { string[] files = File.ReadAllLines(UpdateFile); FileList = new List <FileAndVersion>(); foreach (string line in files) { string[] spl = line.Split('|'); FileAndVersion file = new FileAndVersion(); file.Filename = spl[0]; file.Date = DateTime.Parse(spl[1]); FileList.Add(file); } } catch (IOException) { if (FirstTry) { FirstTry = false; Thread.Sleep(1000); OpenUpdateFile(); } else { MessageBox.Show("עדכון נכשל שגיאה מספר 421\r\nהפעלה מחדש של התוכנה עשויה לפתור את הבעיה"); Environment.Exit(Environment.ExitCode); } } }
private static bool SerachInTheListFiles(FileAndVersion file) { foreach (FileAndVersion f in FileList) { if (DateTime.Compare(f.Date, file.Date) >= 0 && f.Filename.Trim() == file.Filename.Trim()) { return(true); } } return(false); }
public static void CheckForUpdate() { Thread updatethread; int tempid; // SqlDataReader tempreader; LoadLastUpdateFromFileAndDb(); if (GLOBALVARS.LastSwUpdateDB <= GLOBALVARS.LastSwUpdateFile) { return; } GLOBALVARS.LastSwUpdateFile = DateTime.Now; //START CHECK WHICH FILES ARE UPDATED OpenUpdateFile(); reader = DBFunction.ExecuteReader("Select active,filename,version,[date],id,data from FileUpdates"); string sfilename = Process.GetCurrentProcess().Modules[0].FileName; if (reader.HasRows) { //ThreadPool.QueueUserWorkItem(new WaitCallback(ShowUpdateDialog)); updatethread = new Thread(new ThreadStart(ShowUpdateDialog)); updatethread.IsBackground = true; updatethread.Start(); } UpdatedList = new List <FileAndVersion>(); while (!ThreadFinsihLoading) { } //Loop Until Thread Loaded while (reader.Read()) { FileAndVersion ftemp = new FileAndVersion(); ftemp.Filename = (string)reader["Filename"]; ftemp.Date = (DateTime)reader["Date"]; tempid = (int)reader["id"]; UpdatedList.Add(ftemp); if (!SerachInTheListFiles(ftemp)) { // tempreader= DBFunction.ExecuteReader("Select data from FileUpdates where id=" + tempid); // tempreader.Read(); byte[] data = (byte[])reader["data"]; // tempreader.Close(); winupdate.PbUpdate.Value++; if (((bool)reader["Active"])) { // Check if this is the sw itself File.WriteAllBytes(Application.StartupPath + "//temp.ex", data); File.Move(sfilename, "old.del"); File.Move("temp.ex", sfilename); } else { File.WriteAllBytes(Application.StartupPath + "//" + ftemp.Filename, data); } } else { winupdate.PbUpdate.Value++; } } winupdate.PbUpdate.Value++; reader.Close(); UpdateTheFile(); UpdateLastTimeCheck(DateTime.Now); Process.Start(sfilename); Environment.Exit(Environment.ExitCode); }