/// <summary> /// Returns true if the path points to a folder. False - otherwise. /// </summary> /// <remarks>Throws exception if the file/folder does not exists.</remarks> /// <param name="path">Path to the file or folder.</param> /// <returns>True if the path is folder. False - otherwise.</returns> public static bool IsFolder(string path) { FileAttributes attributes = File.GetAttributes(path); return((attributes & FileAttributes.Directory) == FileAttributes.Directory); }
public static List <FileSystemStorageItemBase> Search(string FolderPath, string TargetName, bool SearchInSubFolders = false, bool IncludeHiddenItem = false, CancellationToken CancelToken = default) { if (string.IsNullOrWhiteSpace(FolderPath)) { throw new ArgumentException("Argument could not be empty", nameof(FolderPath)); } if (string.IsNullOrEmpty(TargetName)) { throw new ArgumentException("Argument could not be empty", nameof(TargetName)); } IntPtr Ptr = FindFirstFileExFromApp(Path.Combine(FolderPath, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH); List <FileSystemStorageItemBase> SearchResult = new List <FileSystemStorageItemBase>(); try { if (Ptr.ToInt64() != -1) { do { FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes; if (IncludeHiddenItem || !Attribute.HasFlag(FileAttributes.Hidden)) { if (Attribute.HasFlag(FileAttributes.Directory)) { if (Data.cFileName != "." && Data.cFileName != "..") { string CurrentDataPath = Path.Combine(FolderPath, Data.cFileName); if (Regex.IsMatch(Data.cFileName, @$ ".*{TargetName}.*", RegexOptions.IgnoreCase)) { FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime); DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc); if (Attribute.HasFlag(FileAttributes.Hidden)) { SearchResult.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, CurrentDataPath, ModifiedTime)); } else { SearchResult.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, CurrentDataPath, ModifiedTime)); } } if (SearchInSubFolders) { SearchResult.AddRange(Search(CurrentDataPath, TargetName, true, IncludeHiddenItem, CancelToken)); } } } else { if (Regex.IsMatch(Data.cFileName, @$ ".*{TargetName}.*", RegexOptions.IgnoreCase)) { string CurrentDataPath = Path.Combine(FolderPath, Data.cFileName); FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime); DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc); if (Attribute.HasFlag(FileAttributes.Hidden)) { SearchResult.Add(new HiddenStorageItem(Data, StorageItemTypes.File, CurrentDataPath, ModifiedTime)); } else { if (!Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase)) { if (Data.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase)) { SearchResult.Add(new HyperlinkStorageItem(Data, CurrentDataPath, ModifiedTime)); } else { SearchResult.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, CurrentDataPath, ModifiedTime)); } } } } } } }while (FindNextFile(Ptr, out Data) && !CancelToken.IsCancellationRequested); return(SearchResult); } else { return(SearchResult); } } catch { return(SearchResult); } finally { FindClose(Ptr); } }
public static void findCrossImport(string pValue) { List <string> tNeedCheck = new List <string> { "_Game20DN", "_Game30M", "_GameBANK", "_GameBBDZ", "_GameBRLZ", "_GameController", "_GameDDZ", "_GameDDZC", "_GameDZNN", "_GameDZPK", "_GameFKBY", "_GameFKTBDN", "_GameFTWZ", "_GameSRFTWZ", "_GameGuide", "_GameHPLZ", "_GameJQNN", "_GameKPNN", "_GameKSQZMJ" }; tNeedCheck.Add("_GameMXNN"); //tNeedCheck.Add("_GameNN"); tNeedCheck.Add("_GameSHHZ"); tNeedCheck.Add("_GameSRNN"); tNeedCheck.Add("_GameSRPS"); tNeedCheck.Add("_GameTBDSZ"); tNeedCheck.Add("_GameTBNN"); tNeedCheck.Add("_GameTBSZ"); tNeedCheck.Add("_GameTBTW"); tNeedCheck.Add("_GameTBWZ"); tNeedCheck.Add("_GameXJ"); tNeedCheck.Add("_GameYSZ"); tNeedCheck.Add("__HappyCity"); tNeedCheck.Add("__HappyCity_510k"); tNeedCheck.Add("__HappyCity_597GD"); tNeedCheck.Add("__HappyCity_597New"); tNeedCheck.Remove(pValue); Object[] objs = Selection.GetFiltered(typeof(Object), SelectionMode.Assets); if (null == objs || objs.Length < 1) { return; } List <string> listFiles = new List <string>(); foreach (Object obj in objs) { string szPath = AssetDatabase.GetAssetPath(obj); System.IO.FileAttributes file_attr = System.IO.File.GetAttributes(szPath); if ((file_attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) { string[] fileEntries = Directory.GetFiles(szPath, "*.*", SearchOption.AllDirectories); if (null != fileEntries && fileEntries.Length > 0) { foreach (string szStr in fileEntries) { if (!listFiles.Contains(szStr)) { listFiles.Add(szStr); } } } } else { if (!listFiles.Contains(szPath)) { listFiles.Add(szPath); } } } string[] allEntries = listFiles.ToArray(); float tNum = 0; for (int i = 0, tLen = allEntries.Length; i < tLen; i++) { string tSearchStr = allEntries[i]; tNum += 1; if (EditorUtility.DisplayCancelableProgressBar(pValue + ": " + tSearchStr, tNum + "/" + allEntries.Length, tNum / allEntries.Length)) { break; } if (tSearchStr.Contains(".meta") || tSearchStr.Contains(".svn") || tSearchStr.Contains(".cs")) { continue; } if (tSearchStr.Contains(".mat")) { // Object obj = AssetDatabase.LoadAssetAtPath(tSearchStr, typeof(Object)); // Material tMaterial = obj as Material; } else if (tSearchStr.Contains(".prefab")) { Object obj = AssetDatabase.LoadAssetAtPath(tSearchStr, typeof(Object)); GameObject ObjInst = obj as GameObject; Object[] tDependObjs = EditorUtility.CollectDependencies(new Object[] { ObjInst }); for (int j = 0, tJLen = tDependObjs.Length; j < tJLen; j++) { Object tDepndObj = tDependObjs[j]; string tObjPath = AssetDatabase.GetAssetPath(tDepndObj); for (int tK = 0, tKlen = tNeedCheck.Count; tK < tKlen; tK++) { if (tObjPath.Contains(tNeedCheck[tK] + "/") && tObjPath.Contains(".cs") == false) { Debug.Log(tSearchStr + " 交叉引用 :" + tObjPath); break; } } } } } EditorUtility.ClearProgressBar(); Debug.Log("check cross finish"); }
bool Show(System.IO.FileAttributes attributes) { // TODO: Show Hidden return(true); }
public static void SetAttributes(Hierarchy hierarchy, string path, SIO.FileAttributes fileAttributes) { throw new NotImplementedException("KSPe.IO.File.SetAttributes"); }
public int SetFileAttributes(string filename, System.IO.FileAttributes attr, DokanFileInfo info) { Console.WriteLine("SFA " + filename); return(-DokanNet.ERROR_ACCESS_DENIED); }
protected void ChangeProductVersion() { if (!File.Exists(m_sIsmFile)) { return; } System.IO.FileAttributes fileAttribs = File.GetAttributes(m_sIsmFile); const string TEMP_FILE_EXT = ".tmp"; string sTempFile = m_sIsmFile + TEMP_FILE_EXT; if (File.Exists(sTempFile)) { File.SetAttributes(sTempFile, System.IO.FileAttributes.Normal); File.Delete(sTempFile); } bool bReplaced = false; try { using (StreamWriter sw = new StreamWriter(sTempFile)) { using (StreamReader sr = new StreamReader(m_sIsmFile)) { const string BEGIN_PROPERTY_TABLE = "<table name=\"Property\">"; const string END_TABLE = "</table>"; const string END_OF_ELEMENT_START_OF_NEW = "</td><td>"; const string ELEM_VALUE_TO_REPLACE = "ProductVersion"; bool bFoundPropertySection = false; bool bFoundEndOfPropertySection = false; int nPos = -1; string sLine; while ((sLine = sr.ReadLine()) != null) { if (!bReplaced && !bFoundEndOfPropertySection) { if (bFoundPropertySection) { bFoundEndOfPropertySection = (-1 < sLine.LastIndexOf(END_TABLE)); } else { bFoundPropertySection = (-1 < sLine.LastIndexOf(BEGIN_PROPERTY_TABLE)); } if (!bFoundEndOfPropertySection && bFoundPropertySection && -1 < (nPos = sLine.LastIndexOf(ELEM_VALUE_TO_REPLACE))) { // Found "ProductVersion" nPos += ELEM_VALUE_TO_REPLACE.Length + END_OF_ELEMENT_START_OF_NEW.Length; string sBegin = sLine.Substring(0, nPos); // Find the end of the ProductVersion value // (if the version is "1.0.0.0", find the // position of the last '0') while (sLine[nPos++] != '<') { ; } --nPos; string sEnd = sLine.Substring(nPos, sLine.Length - nPos); sLine = sBegin + m_sUpdateProductVersion + sEnd; bReplaced = true; } } sw.WriteLine(sLine); } } } if (bReplaced) { File.SetAttributes(m_sIsmFile, System.IO.FileAttributes.Normal); File.Delete(m_sIsmFile); File.Move(sTempFile, m_sIsmFile); File.SetAttributes(m_sIsmFile, fileAttribs); } } catch (Exception ex) { Debug.Assert(false, ex.ToString(), ex.Message); return; } Debug.Assert(bReplaced); }
/// <summary> /// Converts a <strong>System.IO.FileAttributes</strong> value to /// <strong>DigitalRune.Storages.FileAttributes</strong>. /// </summary> /// <param name="value">The <strong>System.IO.FileAttributes</strong> value.</param> /// <returns>The <strong>DigitalRune.Storages.FileAttributes</strong> value.</returns> public static FileAttributes FromSystemIO(System.IO.FileAttributes value) { return (FileAttributes)value; }
internal static extern SafeFileHandle CreateFile(String lpFileName, System.IO.FileAccess dwDesiredAccess, System.IO.FileShare dwShareMode, SECURITY_ATTRIBUTES lpSecurityAttributes, System.IO.FileMode creationDisposition, System.IO.FileAttributes dwFlagsAndAttributes, IntPtr hTemplateFile);
public static Icon GetFileIcon(string filePath, IconSize size = IconSize.Large, FileIconOptions options = 0, System.IO.FileAttributes attributes = System.IO.FileAttributes.Normal) { var flags = ToFileIconFlags(size, options); var sfi = new UnsafeNativeMethods.SHFILEINFO(); IntPtr sysImageList = UnsafeNativeMethods.SHGetFileInfo(filePath, attributes, ref sfi, UnsafeNativeMethods.SHFILEINFO.Sizeof(), flags); if (sysImageList == IntPtr.Zero) { throw new Win32Exception("SHGetFileIconInfo failed."); } if (sfi.hIcon == IntPtr.Zero) { throw new Win32Exception("SHGetFileIconInfo failed."); } return(HIconToIcon(sfi.hIcon)); }
public int SetFileAttributes(string filename, System.IO.FileAttributes attr, Dokan.DokanFileInfo info) { NotImplemented(); return(-1); }
public void SetAttributes(System.IO.FileAttributes attributes) { Attributes = attributes; }
public void SetFileAttributes(string path, System.IO.FileAttributes attributes) { System.IO.File.SetAttributes(AddExtendedDevicePathPrefix(path), attributes); }
public static List <FileSystemStorageItemBase> GetStorageItems(StorageFolder Folder, bool IncludeHiddenItem, ItemFilters Filter) { if (Folder == null) { throw new ArgumentNullException(nameof(Folder), "Argument could not be null"); } IntPtr Ptr = FindFirstFileExFromApp(Path.Combine(Folder.Path, "*"), FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH); try { if (Ptr.ToInt64() != -1) { List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>(); do { FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes; if (IncludeHiddenItem || !Attribute.HasFlag(FileAttributes.Hidden)) { if (Attribute.HasFlag(FileAttributes.Directory) && Filter.HasFlag(ItemFilters.Folder)) { if (Data.cFileName != "." && Data.cFileName != "..") { FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime); DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc); if (Attribute.HasFlag(FileAttributes.Hidden)) { Result.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime)); } else { Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime)); } } } else if (Filter.HasFlag(ItemFilters.File)) { FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime); DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc); if (Attribute.HasFlag(FileAttributes.Hidden)) { Result.Add(new HiddenStorageItem(Data, StorageItemTypes.File, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime)); } else { if (!Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase)) { if (Data.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase)) { Result.Add(new HyperlinkStorageItem(Data, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime)); } else { Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, Path.Combine(Folder.Path, Data.cFileName), ModifiedTime)); } } } } } }while (FindNextFile(Ptr, out Data)); return(Result); } else { LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error())); return(new List <FileSystemStorageItemBase>()); } } catch { return(new List <FileSystemStorageItemBase>()); } finally { FindClose(Ptr); } }
public int SetFileAttributes(string filename, System.IO.FileAttributes attr, DokanFileInfo info) { Debug("SetFileAttributes {0}", filename); return(DokanNet.DOKAN_SUCCESS); }
/// <summary> /// Fills the row from the array of bytes. /// </summary> unsafe public void FromRawData(byte [] buff, int offs) { if (buff == null) throw new Exception("buff == null"); if (offs + Size > buff.Length) throw new Exception("bounds"); this.Flags = (System.IO.FileAttributes) LEBitConverter.ToUInt32(buff, offs); offs += sizeof (uint); this.Name = LEBitConverter.ToInt32(buff, offs); offs += 4; this.HashValue = LEBitConverter.ToInt32(buff, offs); }
public static bool IsFolder(string path) { System.IO.FileAttributes attr = File.GetAttributes(path); return((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory); }
static void logType(System.IO.FileAttributes attributes, string fn, string addToEnd) { string att = attributes.ToString(); if (att.Contains(',')) { att = att.Split(',')[0]; } switch (att) { case "Archive": Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Compressed": Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Device": Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Yellow; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Directory": Console.ForegroundColor = ConsoleColor.Blue; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Encrypted": Console.BackgroundColor = ConsoleColor.Red; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "IntegrityStream": Console.ForegroundColor = ConsoleColor.Blue; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Hidden": Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Normal": Console.ForegroundColor = ConsoleColor.Green; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "NoScrubData": Console.BackgroundColor = ConsoleColor.Gray; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "NotContentIndexed": Console.BackgroundColor = ConsoleColor.DarkRed; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Offline": Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "ReadOnly": Console.ForegroundColor = ConsoleColor.DarkCyan; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "ReparsePoint": Console.BackgroundColor = ConsoleColor.DarkCyan; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "SparseFile": Console.BackgroundColor = ConsoleColor.DarkYellow; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "System": Console.BackgroundColor = ConsoleColor.DarkBlue; Console.Write(fn + addToEnd); Console.ResetColor(); break; case "Temporary": Console.ForegroundColor = ConsoleColor.Gray; Console.BackgroundColor = ConsoleColor.White; Console.Write(fn + addToEnd); Console.ResetColor(); break; default: Console.Write(fn + addToEnd); break; } }
private static extern bool PathRelativePathTo([Out] StringBuilder pszPath, [In] string pszFrom, [In] System.IO.FileAttributes dwAttrFrom, [In] string pszTo, [In] System.IO.FileAttributes dwAttrTo);
public static void SetAttributes(Hierarchy hierarchy, SIO.FileAttributes fileAttributes, string fn, params string[] fns) { throw new NotImplementedException("KSPe.IO.File.SetAttributes"); }
private void CreateStreams(string filePath, string streamName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, Encoding fileEncoding) { if (File.Exists(filePath) && (this.provider.Force != 0)) { this.oldAttributes = File.GetAttributes(filePath); this.haveOldAttributes = true; System.IO.FileAttributes hidden = System.IO.FileAttributes.Hidden; if ((fileAccess & FileAccess.Write) != 0) { hidden |= System.IO.FileAttributes.ReadOnly; } File.SetAttributes(this.path, File.GetAttributes(filePath) & ~hidden); } FileAccess access = fileAccess; if ((fileAccess & FileAccess.Write) != 0) { fileAccess = FileAccess.ReadWrite; } try { if (!string.IsNullOrEmpty(streamName)) { this.stream = AlternateDataStreamUtilities.CreateFileStream(filePath, streamName, fileMode, fileAccess, fileShare); } else { this.stream = new FileStream(filePath, fileMode, fileAccess, fileShare); } } catch (IOException) { if (!string.IsNullOrEmpty(streamName)) { this.stream = AlternateDataStreamUtilities.CreateFileStream(filePath, streamName, fileMode, access, fileShare); } else { this.stream = new FileStream(filePath, fileMode, access, fileShare); } } if (!this.usingByteEncoding) { if ((fileAccess & FileAccess.Read) != 0) { this.reader = new StreamReader(this.stream, fileEncoding); this._backReader = new FileStreamBackReader(this.stream, fileEncoding); } if ((fileAccess & FileAccess.Write) != 0) { if ((this.reader != null) && ((fileAccess & FileAccess.Read) != 0)) { this.reader.Peek(); fileEncoding = this.reader.CurrentEncoding; } this.writer = new StreamWriter(this.stream, fileEncoding); } } }
public static Alt.IO.FileAttributes ToFileAttributes(System.IO.FileAttributes src) { Alt.IO.FileAttributes dest = (Alt.IO.FileAttributes) 0; if ((src & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) { dest |= Alt.IO.FileAttributes.ReadOnly; } if ((src & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden) { dest |= Alt.IO.FileAttributes.Hidden; } if ((src & System.IO.FileAttributes.System) == System.IO.FileAttributes.System) { dest |= Alt.IO.FileAttributes.System; } if ((src & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) { dest |= Alt.IO.FileAttributes.Directory; } if ((src & System.IO.FileAttributes.Archive) == System.IO.FileAttributes.Archive) { dest |= Alt.IO.FileAttributes.Archive; } if ((src & System.IO.FileAttributes.Device) == System.IO.FileAttributes.Device) { dest |= Alt.IO.FileAttributes.Device; } if ((src & System.IO.FileAttributes.Normal) == System.IO.FileAttributes.Normal) { dest |= Alt.IO.FileAttributes.Normal; } if ((src & System.IO.FileAttributes.Temporary) == System.IO.FileAttributes.Temporary) { dest |= Alt.IO.FileAttributes.Temporary; } if ((src & System.IO.FileAttributes.SparseFile) == System.IO.FileAttributes.SparseFile) { dest |= Alt.IO.FileAttributes.SparseFile; } if ((src & System.IO.FileAttributes.ReparsePoint) == System.IO.FileAttributes.ReparsePoint) { dest |= Alt.IO.FileAttributes.ReparsePoint; } if ((src & System.IO.FileAttributes.Compressed) == System.IO.FileAttributes.Compressed) { dest |= Alt.IO.FileAttributes.Compressed; } if ((src & System.IO.FileAttributes.Offline) == System.IO.FileAttributes.Offline) { dest |= Alt.IO.FileAttributes.Offline; } if ((src & System.IO.FileAttributes.NotContentIndexed) == System.IO.FileAttributes.NotContentIndexed) { dest |= Alt.IO.FileAttributes.NotContentIndexed; } if ((src & System.IO.FileAttributes.Encrypted) == System.IO.FileAttributes.Encrypted) { dest |= Alt.IO.FileAttributes.Encrypted; } return(dest); }
private static bool IsDirectory(string path) { System.IO.FileAttributes fa = System.IO.File.GetAttributes(path); return((fa & FileAttributes.Directory) != 0); }
public static void findCrossUITexture() { Object[] objs = Selection.GetFiltered(typeof(Object), SelectionMode.Assets); if (null == objs || objs.Length < 1) { return; } List <string> listFiles = new List <string>(); foreach (Object obj in objs) { string szPath = AssetDatabase.GetAssetPath(obj); System.IO.FileAttributes file_attr = System.IO.File.GetAttributes(szPath); if ((file_attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory) { string[] fileEntries = Directory.GetFiles(szPath, "*.*", SearchOption.AllDirectories); if (null != fileEntries && fileEntries.Length > 0) { foreach (string szStr in fileEntries) { if (!listFiles.Contains(szStr)) { listFiles.Add(szStr); } } } } else { if (!listFiles.Contains(szPath)) { listFiles.Add(szPath); } } } string[] allEntries = listFiles.ToArray(); foreach (string tSearchStr in allEntries) { if (tSearchStr.Contains(".meta") || tSearchStr.Contains(".svn")) { continue; } if (tSearchStr.Contains(".mat")) { // Object obj = AssetDatabase.LoadAssetAtPath(tSearchStr, typeof(Object)); // Material tMaterial = obj as Material; } else if (tSearchStr.Contains(".prefab")) { Object obj = AssetDatabase.LoadAssetAtPath(tSearchStr, typeof(Object)); GameObject ObjInst = obj as GameObject; UITexture[] tDependObjs = ObjInst.GetComponentsInChildren <UITexture>(); foreach (UITexture tDepndObj in tDependObjs) { Debug.Log(tDepndObj.gameObject.name); } } } }
public static extern bool SetFileAttributesFromApp( string lpFileName, System.IO.FileAttributes dwFileAttributes);
/// <summary> /// Combine all sprites into a single texture and save it to disk. /// </summary> static public bool UpdateTexture(UIAtlas atlas, List <SpriteEntry> sprites) { // Get the texture for the atlas Texture2D tex = atlas.texture as Texture2D; string oldPath = (tex != null) ? AssetDatabase.GetAssetPath(tex.GetInstanceID()) : ""; string newPath = NGUIEditorTools.GetSaveableTexturePath(atlas); // Clear the read-only flag in texture file attributes if (System.IO.File.Exists(newPath)) { #if !UNITY_4_1 && !UNITY_4_0 && !UNITY_3_5 if (!AssetDatabase.IsOpenForEdit(newPath)) { Debug.LogError(newPath + " is not editable. Did you forget to do a check out?"); return(false); } #endif System.IO.FileAttributes newPathAttrs = System.IO.File.GetAttributes(newPath); newPathAttrs &= ~System.IO.FileAttributes.ReadOnly; System.IO.File.SetAttributes(newPath, newPathAttrs); } bool newTexture = (tex == null || oldPath != newPath); if (newTexture) { // Create a new texture for the atlas tex = new Texture2D(1, 1, TextureFormat.ARGB32, false); } else { // Make the atlas readable so we can save it tex = NGUIEditorTools.ImportTexture(oldPath, true, false, false); } // Pack the sprites into this texture if (PackTextures(tex, sprites)) { byte[] bytes = tex.EncodeToPNG(); System.IO.File.WriteAllBytes(newPath, bytes); bytes = null; // Load the texture we just saved as a Texture2D AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); tex = NGUIEditorTools.ImportTexture(newPath, false, true, !atlas.premultipliedAlpha); // Update the atlas texture if (newTexture) { if (tex == null) { Debug.LogError("Failed to load the created atlas saved as " + newPath); } else { atlas.spriteMaterial.mainTexture = tex; } ReleaseSprites(sprites); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport); } return(true); } else { if (!newTexture) { NGUIEditorTools.ImportTexture(oldPath, false, true, !atlas.premultipliedAlpha); } //Debug.LogError("Operation canceled: The selected sprites can't fit into the atlas.\n" + // "Keep large sprites outside the atlas (use UITexture), and/or use multiple atlases instead."); EditorUtility.DisplayDialog("Operation Canceled", "The selected sprites can't fit into the atlas.\n" + "Keep large sprites outside the atlas (use UITexture), and/or use multiple atlases instead", "OK"); return(false); } }
public void SetFileAttributes(string path, System.IO.FileAttributes attributes) { System.IO.File.SetAttributes(PrefixWithUNC(path), attributes); }
//Implements SaveAs functionality private void SaveAs() { saveFileDialog1.Filter = "db files (*.db)|*.db|All files (*.*)|*.*"; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { string newName = saveFileDialog1.FileName; //Should never be hit if (null == database) { System.Windows.Forms.MessageBox.Show("No database is open", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand, System.Windows.Forms.MessageBoxDefaultButton.Button1); } else if (IsReadOnly(newName)) { string errMsg = String.Format("File {0} is read only! \nSave the file under different name?", newName); DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg, "Error", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Hand, System.Windows.Forms.MessageBoxDefaultButton.Button1); if (DialogResult.Yes == result) { this.SaveAs(); } } else { //If the source file is read only the CopyTo method will also create a ReadOnly file //Take the new file and remove the ReadOnly attribute in order to be able to save any new changes System.IO.FileAttributes attribute = new System.IO.FileAttributes(); FileInfo oldDbFile = new FileInfo(database.GetName()); oldDbFile.CopyTo(newName, true); if (IsReadOnly(database.GetName())) { FileInfo newDbFile = new FileInfo(newName); newDbFile.Attributes = FileAttributes.Archive; } //Open the new file database.Close(); database = new SqliteDb(); database.Open(newName); this.SaveDatabase(); this.OpenDatabase(newName); } } }
public static void SetAttributes(string path, MSIO.FileAttributes fileAttributes) => MSIOF.SetAttributes(path, fileAttributes);
public static List <FileSystemStorageItemBase> GetStorageItems(params string[] PathArray) { if (PathArray.Length == 0 || PathArray.Any((Item) => string.IsNullOrWhiteSpace(Item))) { throw new ArgumentException("Argument could not be empty", nameof(PathArray)); } if (PathArray.Any((Item) => Path.GetPathRoot(Item) == Item)) { throw new ArgumentException("Unsupport for root directory", nameof(PathArray)); } try { List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>(PathArray.Length); foreach (string Path in PathArray) { IntPtr Ptr = FindFirstFileExFromApp(Path, FINDEX_INFO_LEVELS.FindExInfoBasic, out WIN32_FIND_DATA Data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, FIND_FIRST_EX_LARGE_FETCH); try { if (Ptr.ToInt64() != -1) { FileAttributes Attribute = (FileAttributes)Data.dwFileAttributes; if (Attribute.HasFlag(FileAttributes.Directory)) { if (Data.cFileName != "." && Data.cFileName != "..") { FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime); DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc); if (Attribute.HasFlag(FileAttributes.Hidden)) { Result.Add(new HiddenStorageItem(Data, StorageItemTypes.Folder, Path, ModifiedTime)); } else { Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.Folder, Path, ModifiedTime)); } } } else { FileTimeToSystemTime(ref Data.ftLastWriteTime, out SYSTEMTIME ModTime); DateTime ModifiedTime = new DateTime(ModTime.Year, ModTime.Month, ModTime.Day, ModTime.Hour, ModTime.Minute, ModTime.Second, ModTime.Milliseconds, DateTimeKind.Utc); if (Attribute.HasFlag(FileAttributes.Hidden)) { Result.Add(new HiddenStorageItem(Data, StorageItemTypes.File, Path, ModifiedTime)); } else { if (!Data.cFileName.EndsWith(".url", StringComparison.OrdinalIgnoreCase)) { if (Data.cFileName.EndsWith(".lnk", StringComparison.OrdinalIgnoreCase)) { Result.Add(new HyperlinkStorageItem(Data, Path, ModifiedTime)); } else { Result.Add(new FileSystemStorageItemBase(Data, StorageItemTypes.File, Path, ModifiedTime)); } } } } } else { LogTracer.Log(new Win32Exception(Marshal.GetLastWin32Error())); } } finally { FindClose(Ptr); } } return(Result); } catch { return(new List <FileSystemStorageItemBase>()); } }
public NtStatus CreateFile(string filename, FileAccess access, System.IO.FileShare share, System.IO.FileMode mode, System.IO.FileOptions options, System.IO.FileAttributes attributes, DokanFileInfo info) { var node = GetNodeFast(filename, info); if (node == null) { if (access == FileAccess.Delete) { return(DokanResult.Success); //already gone } switch (mode) { case FileMode.CreateNew: case FileMode.Create: case FileMode.OpenOrCreate: if (filename.Length == 0) { return(NtStatus.Success); } string Directory = filename; if (!info.IsDirectory) //Directory doesn't have a filename that we want to cut off { Directory = filename.Substring(0, filename.LastIndexOf('\\')); if (Directory.Length == 0) { Directory = "\\"; } } var nodeDirectory = CreateOrFindDirectoryRecursive(Directory); if (!(nodeDirectory is PboFsRealFolder) && nodeDirectory is PboFsFolder virtualFolder) { nodeDirectory = fileTree.MakeDirectoryWriteable(virtualFolder); } if (nodeDirectory is PboFsRealFolder folder) { if (info.IsDirectory) { info.Context = nodeDirectory; //Nothing else to do as full path is already included in DirectoryPath } else { //Filename without folder path var FileNameDirect = filename.Substring(filename.LastIndexOf('\\')); var FileNameDirectNoLeadingSlash = filename.Substring(filename.LastIndexOf('\\') + 1); FileStream newStream = null; try { newStream = System.IO.File.Create(folder.path + FileNameDirect); } catch (Exception e) { Console.WriteLine(e); return(DokanResult.AccessDenied); //#TODO correct result for exception type } var rlFile = new PboFsRealFile(new System.IO.FileInfo(folder.path + FileNameDirect), folder, newStream); folder.Children[FileNameDirectNoLeadingSlash.ToLower()] = rlFile; fileTree.AddNode(rlFile); info.Context = rlFile; } return(DokanResult.Success); } return(DokanResult.DiskFull); case FileMode.Open: case FileMode.Truncate: case FileMode.Append: return(DokanResult.FileNotFound); } } info.Context = node; if (node is PboFsFolder && !info.IsDirectory) { info.IsDirectory = true; //Dokan documentation says we need to do that. } if (mode == FileMode.CreateNew) { return(DokanResult.FileExists); } if (access == FileAccess.Delete) { NtStatus deleteResult = DokanResult.NotImplemented; if (node is PboFsRealFile) { deleteResult = DeleteFile(filename, info); } else if (node is PboFsRealFolder) { deleteResult = DeleteDirectory(filename, info); } return(deleteResult); } bool wantsWrite = (access & (FileAccess.WriteData | FileAccess.AppendData | FileAccess.Delete | FileAccess.GenericWrite) ) != 0; bool wantsRead = (access & (FileAccess.ReadData | FileAccess.GenericRead | FileAccess.Execute | FileAccess.GenericExecute) ) != 0; if (wantsWrite && !(node is IPboFsRealObject)) { return(DokanResult.AccessDenied); } if (node is IPboFsFile file && (wantsRead || wantsWrite)) { return(file.Open(wantsWrite, mode)); } return(DokanResult.Success); }
/// <summary> /// Saves the current console info into a file. /// </summary> protected override void ProcessRecord() { // Get filename.. string file = GetFileName(); // if file is null or empty..prompt the user for filename if (string.IsNullOrEmpty(file)) { file = PromptUserForFile(); } // if file is still empty..write error and back out.. if (string.IsNullOrEmpty(file)) { PSArgumentException ae = PSTraceSource.NewArgumentException("file", ConsoleInfoErrorStrings.FileNameNotResolved); ThrowError(file, "FileNameNotResolved", ae, ErrorCategory.InvalidArgument); } if (WildcardPattern.ContainsWildcardCharacters(file)) { ThrowError(file, "WildCardNotSupported", PSTraceSource.NewInvalidOperationException(ConsoleInfoErrorStrings.ConsoleFileWildCardsNotSupported, file), ErrorCategory.InvalidOperation); } // Ofcourse, you cant write to a file from HKLM: etc.. string resolvedPath = ResolveProviderAndPath(file); // If resolvedPath is empty just return.. if (string.IsNullOrEmpty(resolvedPath)) { return; } // Check whether the file ends with valid extension if (!resolvedPath.EndsWith(StringLiterals.PowerShellConsoleFileExtension, StringComparison.OrdinalIgnoreCase)) { // file does not end with proper extension..create one.. resolvedPath = resolvedPath + StringLiterals.PowerShellConsoleFileExtension; } if (!ShouldProcess(this.Path)) // should this be resolvedPath? { return; } //check if destination file exists. if (File.Exists(resolvedPath)) { if (NoClobber) { string message = StringUtil.Format( ConsoleInfoErrorStrings.FileExistsNoClobber, resolvedPath, "NoClobber"); // prevents localization Exception uae = new UnauthorizedAccessException(message); ErrorRecord errorRecord = new ErrorRecord( uae, "NoClobber", ErrorCategory.ResourceExists, resolvedPath); // NOTE: this call will throw ThrowTerminatingError(errorRecord); } // Check if the file is read-only System.IO.FileAttributes attrib = System.IO.File.GetAttributes(resolvedPath); if ((attrib & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) { if (Force) { RemoveFileThrowIfError(resolvedPath); // Note, we do not attempt to set read-only on the new file } else { ThrowError(file, "ConsoleFileReadOnly", PSTraceSource.NewArgumentException(file, ConsoleInfoErrorStrings.ConsoleFileReadOnly, resolvedPath), ErrorCategory.InvalidArgument); } } } try { if (this.Runspace != null) { this.Runspace.SaveAsConsoleFile(resolvedPath); } else if (InitialSessionState != null) { this.InitialSessionState.SaveAsConsoleFile(resolvedPath); } else { Dbg.Assert(false, "Both RunspaceConfiguration and InitialSessionState should not be null"); throw PSTraceSource.NewInvalidOperationException(ConsoleInfoErrorStrings.CmdletNotAvailable); } } catch (PSArgumentException mae) { ThrowError(resolvedPath, "PathNotAbsolute", mae, ErrorCategory.InvalidArgument); } catch (PSArgumentNullException mane) { ThrowError(resolvedPath, "PathNull", mane, ErrorCategory.InvalidArgument); } catch (ArgumentException ae) { ThrowError(resolvedPath, "InvalidCharactersInPath", ae, ErrorCategory.InvalidArgument); } // looks like saving succeeded. // Now try changing $console Exception e = null; try { //Update $Console variable Context.EngineSessionState.SetConsoleVariable(); } catch (ArgumentNullException ane) { e = ane; } catch (ArgumentOutOfRangeException aor) { e = aor; } catch (ArgumentException ae) { e = ae; } catch (SessionStateUnauthorizedAccessException sue) { e = sue; } catch (SessionStateOverflowException sof) { e = sof; } catch (ProviderNotFoundException pnf) { e = pnf; } catch (System.Management.Automation.DriveNotFoundException dnfe) { e = dnfe; } catch (NotSupportedException ne) { e = ne; } catch (ProviderInvocationException pin) { e = pin; } if (e != null) { throw PSTraceSource.NewInvalidOperationException(e, ConsoleInfoErrorStrings.ConsoleVariableCannotBeSet, resolvedPath); } }
public DokanError SetFileAttributes(string fileName, System.IO.FileAttributes attributes, DokanFileInfo info) { log.Info(String.Format("SetFileAttributes call - {0}", fileName)); return(DokanError.ErrorError); }