void DoCp(pluginner.IFSPlugin SourceFS, pluginner.IFSPlugin DestinationFS, pluginner.File SourceFile, string DestinationURL, AsyncCopy AC) { ReplaceQuestionDialog.ClickedButton Placeholder = ReplaceQuestionDialog.ClickedButton.Cancel; DoCp( SourceFS, DestinationFS, SourceFile, DestinationURL, ref Placeholder, AC ); }
public void OpenFile(string url, pluginner.IFSPlugin fsplugin) { lblFileName.Text = url; fileContent = fsplugin.GetFileContent(url); ChangeCodepage(Codepage); }
/// <summary> /// Background file remove /// </summary> /// <param name="url">url of the file</param> /// <param name="fs">filesystem of the file</param> private void DoRmFile(string url, pluginner.IFSPlugin fs) { try { fs.DeleteFile(url); } catch (Exception err) { Utilities.ShowError(err.Message, null); } }
/// <summary> /// Background directory remove /// </summary> /// <param name="url">url of the file</param> /// <param name="fs">filesystem of the file</param> private void DoRmDir(string url, pluginner.IFSPlugin fs) { try { fs.DeleteDirectory(url, true); } catch (pluginner.ThisDirCannotBeRemovedException) { Utilities.ShowWarning(string.Format(Localizator.GetString("DirCantBeRemoved")),url); } catch (Exception err) { Utilities.ShowError(err.Message); } }
/// <summary> /// Copy the entrie directory /// </summary> private void DoCpDir(string source, string destination, pluginner.IFSPlugin fsa, pluginner.IFSPlugin fsb) { if (!fsb.DirectoryExists(destination)) { fsb.CreateDirectory(destination); } fsb.CurrentDirectory = destination; foreach (DirItem di in fsa.DirectoryContent) { if (di.TextToShow == "..") { /* don't touch the link to the parent directory */} else if (!di.IsDirectory) { //it is file string s1 = di.URL; //source url FSEntryMetadata md1 = fsa.GetMetadata(s1); string s2 = destination + fsb.DirSeparator + md1.Name; //destination url ReplaceQuestionDialog.ClickedButton Placeholder = ReplaceQuestionDialog.ClickedButton.Cancel; DoCp(fsa, fsb, s1, s2, ref Placeholder, new AsyncCopy()); } else if (di.IsDirectory) { //it is subdirectory DoCpDir(di.URL, destination + fsb.DirSeparator + di.TextToShow, fsa,fsb); } } }
public void WriteFile(pluginner.File NewFile, int Progress, byte[] Content) { //запись файла _CheckProtocol(NewFile.Path); string InternalURL = NewFile.Path.Replace("file://", ""); try{ Progress = 10; pluginner.File f = NewFile; if(!Directory.Exists(InternalURL)) File.WriteAllBytes(InternalURL, Content); Progress = 25; if (!Directory.Exists(InternalURL)) File.SetAttributes(InternalURL, f.Metadata.Attrubutes); Progress = 50; File.SetCreationTime(InternalURL, f.Metadata.CreationTimeUTC); Progress = 75; File.SetLastWriteTime(InternalURL, DateTime.Now); Progress = 100; } catch (Exception ex){ //System.Windows.Forms.MessageBox.Show(ex.Message,"LocalFS error",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Stop); new MsgBox(ex.Message, null, MsgBox.MsgBoxType.Error); Console.Write(ex.Message + "\n" + ex.StackTrace + "\n" + "Catched in local fs provider while writing " + InternalURL + "\n"); } }
public void Touch(pluginner.FSEntryMetadata Metadata) { string url = Metadata.FullURL; _CheckProtocol(url); string InternalURL = url.Replace("file://", ""); if (!Directory.Exists(InternalURL) && !File.Exists(InternalURL)) { StreamWriter sw = File.CreateText(InternalURL); sw.Close(); sw.Dispose(); } try { File.SetAttributes(InternalURL, Metadata.Attrubutes); File.SetCreationTime(InternalURL, Metadata.CreationTimeUTC); File.SetLastWriteTime(InternalURL, DateTime.Now); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void LoadFile(string url, pluginner.IFSPlugin fsplugin) { URL = url; FS = fsplugin; Content = Encoding.UTF8.GetString(fsplugin.GetFile (url, new int()).Content); }
/// <summary> /// Background file copier /// </summary> /// <param name='SourceFS'> /// Source FS. /// </param> /// <param name='DestinationFS'> /// Destination FS. /// </param> /// <param name='SourceFile'> /// Source file. /// </param> /// <param name='DestinationURL'> /// Destination URL. /// </param> /// <param name='SkipAll'> /// The referenced variable will be set to TRUE if user chooses "Skip all" /// </param> /// <param name='ReplaceAll'> /// The referenced variable will be set to TRUE if user chooses "Replace all" /// </param> void DoCp(pluginner.IFSPlugin SourceFS, pluginner.IFSPlugin DestinationFS, pluginner.File SourceFile, string DestinationURL, ref ReplaceQuestionDialog.ClickedButton Feedback, AsyncCopy AC) { pluginner.File NewFile = SourceFile; NewFile.Path = DestinationURL; if (SourceFile.Path == DestinationURL){ string itself = Locale.GetString("CantCopySelf"); string toshow = string.Format(Locale.GetString("CantCopy"), SourceFile.Name, itself); Xwt.Application.Invoke(new Action(delegate { Xwt.MessageDialog.ShowWarning(toshow); })); //calling the msgbox in non-main threads causes some UI bugs, so push this call into main thread return; } if(DestinationFS.FileExists (DestinationURL)){ ReplaceQuestionDialog rpd = null; bool ready = false; Xwt.Application.Invoke( new Action( delegate { rpd = new ReplaceQuestionDialog(DestinationFS.GetFile(DestinationURL, new double()).Name); ready = true; } ) ); do { } while (!ready); ready = false; var ClickedButton = ReplaceQuestionDialog.ClickedButton.Skip; Xwt.Application.Invoke( new Action( delegate { ClickedButton = rpd.Run(); ready = true; } ) ); do {} while (!ready); switch(ClickedButton){ case ReplaceQuestionDialog.ClickedButton.Replace: //continue execution Feedback = rpd.ChoosedButton; break; case ReplaceQuestionDialog.ClickedButton.ReplaceAll: //continue execution Feedback = rpd.ChoosedButton; break; case ReplaceQuestionDialog.ClickedButton.ReplaceOld: Feedback = rpd.ChoosedButton; if(SourceFS.GetMetadata(SourceFile.Path).LastWriteTimeUTC < DestinationFS.GetFile(DestinationURL,new double()).Metadata.LastWriteTimeUTC) {/*continue execution*/} else {return;} break; case ReplaceQuestionDialog.ClickedButton.Skip: Feedback = rpd.ChoosedButton; return; case ReplaceQuestionDialog.ClickedButton.SkipAll: Feedback = rpd.ChoosedButton; return; } } try { pluginner.FSEntryMetadata md = SourceFS.GetMetadata(SourceFile.Path); md.FullURL = NewFile.Path; System.IO.Stream SrcStream = SourceFS.GetStream(SourceFile.Path); DestinationFS.Touch(md); System.IO.Stream DestStream = DestinationFS.GetStream(DestinationURL,true); if(AC == null) AC = new AsyncCopy(); bool CpComplete = false; AC.OnComplete+=(rezultat)=>{ CpComplete = true; }; //warning: due to some GTK# bugs, buffer sizes lesser than 128KB may cause //an StackOverflowException at UI update code AC.CopyFile(SrcStream, DestStream, 131072); //buffer is 1/8 megabyte do{ /*nothing*/ } while(!CpComplete); //don't stop this thread until the copy is finished return; } catch (Exception ex) { if (ex.GetType() != typeof(System.Threading.ThreadAbortException)) { pluginner.Utilities.ShowMessage(string.Format(Locale.GetString("CantCopy"),SourceFile.Name,ex.Message)); Console.WriteLine("Cannot copy because of {0}({1}) at \n{2}.", ex.GetType(), ex.Message, ex.StackTrace); } } }
/// <summary> /// Background directory remove /// </summary> /// <param name="url">url of the file</param> /// <param name="fs">filesystem of the file</param> void DoRmDir(string url, pluginner.IFSPlugin fs) { try { fs.DeleteDirectory(url, true); } catch (pluginner.ThisDirCannotBeRemovedException) { new MsgBox(url, string.Format(Locale.GetString("DirCantBeRemoved"), url), MsgBox.MsgBoxType.Warning); } catch (Exception err) { new MsgBox(err.Message, null, MsgBox.MsgBoxType.Error); } }
/// <summary> /// Copy the entrie directory /// </summary> private void DoCpDir(string source, string destination, pluginner.IFSPlugin fsa, pluginner.IFSPlugin fsb) { if (!fsb.DirectoryExists(destination)) { fsb.CreateDirectory(destination); } fsb.CurrentDirectory = destination; foreach (DirItem di in fsa.DirectoryContent) { if (di.TextToShow == "..") { /* don't touch the link to the parent directory */} else if (!di.IsDirectory) { //it is file string s1 = di.Path; //source url FSEntryMetadata md1 = fsa.GetMetadata(s1); string s2 = destination + fsb.DirSeparator + md1.Name; //destination url DoCp(fsa, fsb, fsa.GetFile(s1, new double()), s2, new AsyncCopy()); } else if (di.IsDirectory) { //it is subdirectory DoCpDir(di.Path, destination + fsb.DirSeparator + di.TextToShow, fsa,fsb); } } }
/// <summary>Switches the active panel</summary> /// <param name="NewPanel">The new active panel</param> private void SwitchPanel(pluginner.FileListPanel NewPanel) { if (NewPanel == ActivePanel) return; PassivePanel = ActivePanel; ActivePanel = NewPanel; #if DEBUG string PanelName = (NewPanel == p1) ? "LEFT" : "RIGHT"; Console.WriteLine("FOCUS DEBUG: The " + PanelName + " panel (" + NewPanel.FS.CurrentDirectory + ") got focus"); #endif this.Title = string.Format( "{0} {1} - {2}", Winforms.Application.ProductName, Winforms.Application.ProductVersion, ActivePanel.FS.CurrentDirectory ); PassivePanel.UrlBox.BackgroundColor = Xwt.Drawing.Colors.LightBlue; ActivePanel.UrlBox.BackgroundColor = Xwt.Drawing.Colors.DodgerBlue; }
/// <summary>Load the file in the VE</summary> /// <param name="URL">The URL of the file</param> /// <param name="FS">The filesystem of the file</param> /// <param name="plugin">The VE plugin, which will be used to load this file</param> /// <param name="AllowEdit">Allow editing the file</param> public void LoadFile(string URL, pluginner.IFSPlugin FS, pluginner.IVEPlugin plugin, bool AllowEdit) { //check for external editor try{ if (fcmd.Properties.Settings.Default.UseExternalEditor && AllowEdit || fcmd.Properties.Settings.Default.UseExternalViewer && !AllowEdit && URL.StartsWith("file:")){ CanBeShowed = false; if (AllowEdit){ ExecuteProgram(fcmd.Properties.Settings.Default.ExternalEditor.Replace("$", "\"" + URL)); } else{ ExecuteProgram(fcmd.Properties.Settings.Default.ExternalViewer.Replace("$", "\"" + URL)); } return; } } catch (Exception ex) { Xwt.MessageDialog.ShowError(Locale.GetString("CantRunEXE"), ex.Message); CanBeShowed = false; return; } string FiNa4Title = URL.Substring(URL.LastIndexOf(FS.DirSeparator) + 1); IsEditor = AllowEdit; if(AllowEdit) this.Title = string.Format(Locale.GetString("FCETitle"), FiNa4Title); else this.Title = string.Format(Locale.GetString("FCVTitle"), FiNa4Title); FileProcessDialog ProgressDialog = new FileProcessDialog(); string ProgressInitialText = String.Format(Locale.GetString("FCVELoadingMsg"),URL); ProgressDialog.lblStatus.Text = ProgressInitialText; FS.ProgressChanged += (d) => { ProgressDialog.pbrProgress.Fraction = (d >= 0 && d <= 1) ? d : ProgressDialog.pbrProgress.Fraction; Xwt.Application.MainLoop.DispatchPendingEvents(); }; FS.StatusChanged += (d) => { ProgressDialog.lblStatus.Text = ProgressInitialText + "\n" + d; Xwt.Application.MainLoop.DispatchPendingEvents(); }; ProgressDialog.cmdCancel.Clicked += (o, ea) => { CanBeShowed = false; ProgressDialog.Hide(); return; }; ProgressDialog.Show(); Xwt.Application.MainLoop.DispatchPendingEvents(); if (!CanBeShowed) return; Plugin = plugin; Plugin.ReadOnly = !AllowEdit; Plugin.OpenFile(URL, FS); Plugin.ShowToolbar = fcmd.Properties.Settings.Default.VE_ShowToolbar; Plugin.Stylist = s; mnuFormat.SubMenu = Plugin.FormatMenu; bool Mode = AllowEdit; if (!Plugin.CanEdit && AllowEdit) { Xwt.MessageDialog.ShowWarning(String.Format(Locale.GetString("FCVEpluginro1"), Plugin.Name + " " + Plugin.Version), Locale.GetString("FCVEpluginro2")); Mode = false; } FSPlugin = FS; PluginBody = Plugin.Body; SetVEMode(Mode); BuildLayout(); ProgressDialog.Hide(); PluginBody.KeyReleased += (sender, e) => { if(e.Key == Xwt.Key.Escape) CommandBox.SetFocus(); if(e.Key == Xwt.Key.q) this.OnCloseRequested(); }; }
/// <summary>Load the file in the VE (with plugin autodetection)</summary> /// <param name="URL">The file's URL</param> /// <param name="FS">The file's filesystem</param> /// <param name="AllowEdit">Mode of VE: true=editor, false=viewer</param> public void LoadFile(string URL, pluginner.IFSPlugin FS, bool AllowEdit) { byte[] ContentBytes = FS.GetFileContent(URL); string content = (ContentBytes != null && ContentBytes.Length > 0) ? Encoding.UTF8.GetString(ContentBytes) : ""; pluginfinder pf = new pluginfinder(); try { string GottenHeaders; if (content.Length >= 20) GottenHeaders = content.Substring(0, 20); else GottenHeaders = content; LoadFile(URL, FS, pf.GetFCVEplugin("NAME=" + URL + "HEADERS=" + GottenHeaders), AllowEdit); } catch (pluginfinder.PluginNotFoundException ex) { Console.WriteLine("ERROR: VE plugin is not loaded: " + ex.Message + "\n" + ex.StackTrace); Xwt.MessageDialog.ShowError(Locale.GetString("FCVE_PluginNotFound")); LoadFile(URL, FS, new base_plugins.ve.PlainText(), AllowEdit); } catch (Exception ex) { Xwt.MessageDialog.ShowError(string.Format(Locale.GetString("FCVE_LoadError"),ex.Message)); Console.WriteLine("ERROR: VE can't load file: " + ex.Message + "\n" + ex.StackTrace); return; } }