/// <summary> /// Create a new document (from the ShellNew context menu) on the filesystem. Add the document /// to the share if AddToShare is set to true. /// </summary> /// <param name="relPath">Relative path in which the file must be added, not slash terminated.</param> /// <param name="filename">Filename of the new document.</param> public void AddNewDocument(String relPath, String filename, NewDocument doc, bool AddToShare) { GateEntry("AddNewDocument"); try { string fullPath = Share.MakeAbsolute(relPath); // If adding the file to the share, create it in // a temporary location and call AddExternal on the files. if (AddToShare) { String tempDir = Path.GetTempFileName(); File.Delete(tempDir); Directory.CreateDirectory(tempDir); doc.DoVerbAction(KfsPath.AddTrailingSlash(tempDir), filename); List<String> newFile = new List<string>(); newFile.Add(KfsPath.AddTrailingSlash(tempDir) + filename); AddExternalFiles(relPath, newFile.ToArray(), false, new GateConfirmActions()); } // Otherwise, create the file where it was asked. else { doc.DoVerbAction(KfsPath.AddTrailingSlash(fullPath), filename); } } catch (Exception ex) { HandleException(ex); } GateExit("AddDirectory"); }
/// <summary> /// Return true if the NewDocument is desired in our list. /// </summary> private static bool IsNewDocumentWanted(NewDocument doc) { if (doc == null) return false; return (doc.Extension != ".lnk" && doc.Extension != ".lnk2" && doc.Extension != ".bfc" && doc.Extension != ".jnl" && doc.Extension != ".zip"); }
/// <summary> /// Try to create a new NewDocument object. Returns null if impossible. /// </summary> /// <param name="rootKey">ShellNew key's parent.</param> /// <param name="extension">Type extension/param> /// <param name="progID">Type ProgID.</param> /// <returns></returns> public static NewDocument GetNewDoc(RegistryKey ParentKey, String Extension, String ProgID) { Debug.Assert(Extension.StartsWith(".")); Debug.Assert(ProgID != ""); RegistryKey ShellNewKey = null; RegistryKey ProgIDKey = null; NewDocument retValue = new NewDocument(); retValue.Extension = Extension; retValue.ProgID = ProgID; try { // Get the verbs list for this key. There can be multiple ones. If more // than one verb is present, use them with the right priority order. ShellNewKey = ParentKey.OpenSubKey("ShellNew"); foreach (String strShellNewContent in ShellNewKey.GetValueNames()) { Verb v = null; if (strShellNewContent == "Command" || strShellNewContent == "FileName") { Debug.Assert(ShellNewKey.GetValueKind(strShellNewContent) == RegistryValueKind.String || ShellNewKey.GetValueKind(strShellNewContent) == RegistryValueKind.ExpandString); String value = (String)ShellNewKey.GetValue(strShellNewContent); if (value != null && value != "") v = new Verb(VerbToVerbType(strShellNewContent), value); } else if (strShellNewContent == "Data") { byte[] value = null; if (ShellNewKey.GetValueKind(strShellNewContent) == RegistryValueKind.Binary) { value = (byte[])ShellNewKey.GetValue(strShellNewContent); } else if (ShellNewKey.GetValueKind(strShellNewContent) == RegistryValueKind.String) { // It has been observed that some ShellNew key contained the binary // data in a registry key of type "String". This was unexpected, the // workaround consists of converting the String into a byte array. string str = (string)ShellNewKey.GetValue(strShellNewContent); value = (new UnicodeEncoding()).GetBytes(str); } else { Logging.Log(2, "Data of unknown type: The registry key data is of type " + ShellNewKey.GetValueKind(strShellNewContent).ToString() + "which is not supported"); continue; } if (value != null) v = new Verb(VerbType.Data, value); } else if (strShellNewContent == "NullFile") { v = new Verb(VerbType.Nullfile, ""); } else { Logging.Log(2, "Unknown Verb '" + strShellNewContent + "'"); continue; } if (v != null) retValue.Verbs.Add(v.VerbType, v); } // If no verb is present, abort. if (retValue.Verbs.Count < 1) return null; // Get the display name located in the ProgID key's (Default) value. // Example: HKEY_CLASSES_ROOT\Word.Document.8 ProgIDKey = Registry.ClassesRoot.OpenSubKey(ProgID); // If no DisplayName is present, abort. retValue.DisplayName = (String)ProgIDKey.GetValue(""); if (retValue.DisplayName == null || retValue.DisplayName == "") return null; retValue.TypeIcon = ExtractIcon.GetIcon(Extension, true); } catch (Exception ex) { Logging.Log(2, "An error occured creating the NewDocument structure: " + ex.Message); Logging.LogException(ex); return null; } finally { if (ShellNewKey != null) ShellNewKey.Close(); if (ProgIDKey != null) ProgIDKey.Close(); } return retValue; }