private void touchController(ControllerInfo controller) { if (App.Config.updateTimeStamps.ContainsKey(controller.FileName)) { App.Config.updateTimeStamps.Remove(controller.FileName); } App.Config.updateTimeStamps.Add(controller.FileName, DateTime.Now); }
public void feedRemoteListHtml() { //comments are for debugging //FileStream filestream; ////StreamWriter s = File.CreateText("txt.txt"); String[] splithtml = MobiController.Properties.Resources.remotelist.Split(REMOTE_TABLE_DELIMETER); DirectoryInfo controllerDir; if (Directory.Exists(App.CONTROLLER_DIR)) { controllerDir = new DirectoryInfo(App.CONTROLLER_DIR); } else { controllerDir = Directory.CreateDirectory(App.CONTROLLER_DIR); } //FileStream rs = File.Create(Environment.ExpandEnvironmentVariables("%LOCALAPPDATA%\\MobiController") + "\\asdf.rmt"); //rs.WriteByte(2); //rs.Write(Encoding.UTF8.GetBytes("This is a test string"), 0, Encoding.UTF8.GetByteCount("This is a test string")); //rs.WriteByte(3); //rs.Close(); ////s.WriteLine(splithtml[0].Length.ToString("X")); ////s.WriteLine(splithtml[0]); SocketWriteLine(splithtml[0].Length.ToString("X")); SocketWriteLine(splithtml[0]); String tableEntry; foreach (ControllerInfo controller in ControllerInfo.getInstalledControllers(App.CONTROLLER_DIR)) { string[] meta = Controller.getControllerMeta(controller.Path); //rel="external" so that jquery will reload the header of the remote and re-init the DOM for multipage browsing!!!! tableEntry = "<li ><a rel=\"external\" href=\"/controllers/" + controller.Path.Name + "\"> <h3>" + meta[0] + "</h3><p>" + meta[1] + "</p></a></li>"; SocketWriteLine(tableEntry.Length.ToString("X")); SocketWriteLine(tableEntry); } tableEntry = "<li ><a rel=\"external\" href=\"http://mobicontroller.com/controllers/\"> <h3>Get More Controllers</h3></a></li>"; SocketWriteLine(tableEntry.Length.ToString("X")); SocketWriteLine(tableEntry); SocketWriteLine(splithtml[1].Length.ToString("X")); ////s.WriteLine(splithtml[1].Length.ToString("X")); ////s.WriteLine(splithtml[1]); SocketWriteLine(splithtml[1]); SocketWriteLine("0\r\n"); stream.Flush(); //s.Close(); }
public List <ControllerInfo> needsUpdate() { List <ControllerInfo> lstNeedsUpdate = new List <ControllerInfo>(); if (state == ASYNC_STATE.REFRESHED) { try { foreach (ControllerInfo info in ControllerInfo.getInstalledControllers(App.CONTROLLER_DIR)) { if (App.Config.updateTimeStamps.ContainsKey(info.FileName)) { ControllerInfo officialController = findController(info.FileName); // this way the controller info is synced with mobicontroller.com if (App.Config.updateTimeStamps[info.FileName] <= DateTime.Parse(officialController.Lastupdated)) { lstNeedsUpdate.Add(officialController); } } else { findController(info.FileName); lstNeedsUpdate.Add(info); } } } catch (ControllerInfoException ex) { frmSettings.NotifyBadController(ex); } catch (ArgumentException)// if controller is in the all controller list than add to list. { } } else { RefreshCompleted += recallUpdateControllers; refreshControllers(null, null); } return(lstNeedsUpdate); }
public override bool Equals(object obj) { if (obj == this) { return(true); } if (!(obj is ControllerInfo)) { return(false); } ControllerInfo compareme = (ControllerInfo)obj; try { return(compareme.FileName.Equals(FileName) || (compareme.Name.Equals(Name))); } catch (NullReferenceException) { return(false); } }
public void refreshPurchased() { string hostname = "secure144.inmotionhosting.com"; var request = new HttpRequest("/~r4msof5/releases/MobiController/controllers/listpurchased.php"); try { var thisConnection = App.MainWin.Browser.openSecureConnection(hostname, HttpBrowserEntitiy.PORTS.SSL, hostname); request.cookies = App.MainWin.Browser.SessionCookies; thisConnection.sendRequestAsync(request, (response) => { string[] cs = response.Body.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (!response.Body.Contains("You have not purchased any controllers")) { for (int i = 1; i < cs.Length; i++) // i=1 accounts for apache's weird header { var newConnection = App.MainWin.Browser.openConnection(frmMain.WEB_ROOT, HttpBrowserEntitiy.PORTS.HTTP); HttpResponse htmlresponse = newConnection.sendRequest(new HttpRequest("/controllers/" + cs[i] + "/index.php")); Dispatcher.Invoke(() => { var thisController = new ControllerInfo(false) { Description = "sample description", ImageSource = "http://mobicontroller.com/controllers/" + cs[i] + "/1.png", Lastupdated = "never", FileName = cs[i] }; thisController.Description = HelperClass.stripHtmlParagraph(HelperClass.getIsolatedString("<section>", "</section>", htmlresponse.Body)); thisController.Lastupdated = HelperClass.getIsolatedString("<b> Last Updated: ", "</b>", htmlresponse.Body); purchasedControllers.Add(thisController); State = ASYNC_STATE.REFRESHED; }); } } }); } catch (SocketException) { State = ASYNC_STATE.NOTREFRESHED; } }
private void refreshControllers(object sender, RoutedEventArgs e) { //HelperClass helper = new HelperClass(); State = ASYNC_STATE.REFRESHING; allControllers.Clear(); purchasedControllers.Clear(); try { var thisConnection = App.MainWin.Browser.openConnection(frmMain.WEB_ROOT, 80); { thisConnection.sendRequestAsync(new HttpRequest("/releases/MobiController/controllers/listpaid.php"), (response) => { string[] cs = response.Body.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < cs.Length; i++) // i=1 accounts for apache's weird header { var newConnection = App.MainWin.Browser.openConnection(frmMain.WEB_ROOT, 80); var thisController = new ControllerInfo(false) { Description = "sample description", ImageSource = "http://mobicontroller.com/controllers/" + cs[i] + "/1.png", Lastupdated = "never", FileName = cs[i] }; newConnection.sendRequestAsync(new HttpRequest("/controllers/" + cs[i] + "/index.php"), (htmlresponse) => { Dispatcher.Invoke(() => { thisController.Description = HelperClass.stripHtmlParagraph(HelperClass.getIsolatedString("<section>", "</section>", htmlresponse.Body)); thisController.Lastupdated = HelperClass.getIsolatedString("<b> Last Updated: ", "</b>", htmlresponse.Body); allControllers.Insert(0, thisController); }); }); } }); } thisConnection = App.MainWin.Browser.openConnection(frmMain.WEB_ROOT, 80); // just in case the other thread is slow thisConnection.sendRequestAsync(new HttpRequest("/releases/MobiController/controllers/listfree.php"), (response) => { string[] cs = response.Body.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < cs.Length; i++) // i=1 accounts for apache's weird header { var newConnection = App.MainWin.Browser.openConnection(frmMain.WEB_ROOT, 80); HttpResponse htmlresponse = newConnection.sendRequest(new HttpRequest("/controllers/" + cs[i] + "/index.php")); var thisController = new ControllerInfo(true) { Description = "sample description", ImageSource = "http://mobicontroller.com/controllers/" + cs[i] + "/1.png", Lastupdated = "never", FileName = cs[i] }; Dispatcher.Invoke(() => { //Features</h2><div style='text-align:left'> <div style=\"text-align:center;\"> thisController.Description = HelperClass.stripHtmlParagraph(HelperClass.getIsolatedString("<section>", "</section>", htmlresponse.Body)); thisController.Lastupdated = HelperClass.getIsolatedString("<b> Last Updated: ", "</b>", htmlresponse.Body); allControllers.Add(thisController); }); } }); if (App.MainWin.Browser.SessionCookies.ContainsKey(frmMain.PHP_COOKIE)) { refreshPurchased(); } else { State = ASYNC_STATE.REFRESHED; } } catch (SocketException) { State = ASYNC_STATE.NOTREFRESHED; new MessageBox("Error connecting. Please check your connection.").Show(); } }
private bool downloadController(ControllerInfo controller) { if (downloadingControllers.Contains(controller)) { throw new ArgumentException("Already downloading this controller."); } downloadingControllers.Add(controller); string filepath = App.CONTROLLER_DIR + controller.FileName; if (controller.isfree) { filepath += ".rmt"; } else { filepath += ".ermt"; } Action closeUp = () => { Dispatcher.Invoke(() => prgbar.IsIndeterminate = false); if (File.Exists(filepath + "~")) { File.Delete(filepath); File.Move(filepath + "~", filepath); touchController(controller); Dispatcher.Invoke(() => App.serialize(App.Config)); } Dispatcher.Invoke(() => { if (prgbar.Maximum == prgbar.Value) { prgbar.Value = 0; prgbar.Maximum = 1; } //downloadingControllers.Remove(controller); controller.ImageURI = "/MobiController;component/Resources/check.ico"; finished++; downloadingControllers_CollectionChanged(null, null); }); }; controller.FileLen = 1; controller.Progress = 0; try { if (controller.isfree) { var newConnection = App.MainWin.Browser.openConnection(frmMain.WEB_ROOT, HttpBrowserEntitiy.PORTS.HTTP); if (prgbar.Maximum <= 1) { prgbar.IsIndeterminate = true; prgbar.Value = 0; } newConnection.sendRequestAsync(new HttpRequest("/releases/MobiController/controllers/free/" + controller.FileName + ".rmt"), (response) => { if (response.Status == HttpResponse.ConnectionStatus.OK) { using (var fs = File.Create(filepath + "~")) { newConnection.continueDownload(fs, response, (filelen) => Dispatcher.Invoke(() => { if (prgbar.Maximum <= 1) { prgbar.Maximum = 0; prgbar.IsIndeterminate = false; filelen--; // because maximum is set to 1 } controller.FileLen = filelen; prgbar.Maximum += filelen; }), (read) => Dispatcher.Invoke(() => { prgbar.Value += read; controller.Progress += read; })); } } else { Dispatcher.Invoke(() => new MessageBox("There was an error downloading the controller: " + controller.FileName).Show()); controller.ImageURI = "/MobiController;component/Resources/x.ico"; } closeUp(); }); } else { string hostname = "secure144.inmotionhosting.com"; var thisConnection = App.MainWin.Browser.openSecureConnection(hostname, HttpBrowserEntitiy.PORTS.SSL, hostname); var request = new HttpRequest("/~r4msof5/releases/MobiController/controllers/download.php?file=" + controller.FileName); request.cookies = App.MainWin.Browser.SessionCookies; thisConnection.sendRequestAsync(request, (response) => { bool error = false; if (response.Status == HttpResponse.ConnectionStatus.FORBIDDEN) { Dispatcher.Invoke(() => new MessageBox("You are either not logged in or have not purchased this controller. mobicontroller.com has denied access.").Show()); error = true; } if (response.Status == HttpResponse.ConnectionStatus.FILE_NOT_FOUND) { Dispatcher.Invoke(() => new MessageBox("The file was not found on mobicontroller.com").Show()); error = true; } if (!error) { try { MobiControllerBlackBox.BlackBox.continueSafeDownload(thisConnection, response, App.Config.username, filepath + "~", (filelen) => Dispatcher.Invoke(() => { if (prgbar.Maximum <= 1) { prgbar.Maximum = 0; prgbar.IsIndeterminate = false; filelen--; // because maximum is set to 1 } controller.FileLen = filelen; prgbar.Maximum += filelen; }), (read) => { Dispatcher.Invoke(() => { prgbar.Value += read; controller.Progress += read; }); }); } catch (ConnectionException) { Dispatcher.Invoke(() => new MessageBox("There was an unexpected response from the sever. Download Failed.").Show()); controller.ImageURI = "/MobiController;component/Resources/x.ico"; } } else { controller.ImageURI = "/MobiController;component/Resources/x.ico"; } closeUp(); }); } } catch (IOException) { new MessageBox("Error Saving controller. Make sure it is not loaded and that MobiController has permissions to write to: " + App.APP_DATA_FOLDER).Show(); controller.ImageURI = "/MobiController;component/Resources/x.ico"; return(false); } catch (SocketException) { new MessageBox("Error connecting. Please check your connection.").Show(); controller.ImageURI = "/MobiController;component/Resources/x.ico"; return(false); } return(true); }
private void tabSettings_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (tabSettings.SelectedItem == tabiControllers) { try { ControllerList = new ObservableCollection <ControllerInfo>(ControllerInfo.getInstalledControllers(App.CONTROLLER_DIR)); lstControllers.ItemsSource = ControllerList; } catch (ControllerInfoException ex) { NotifyBadController(ex); } } }