public void TestToString() { var a = new ZlpFileInfo(@"C:\ablage\test.txt"); var b = new FileInfo(@"C:\ablage\test.txt"); var x = a.ToString(); var y = b.ToString(); Assert.AreEqual(x,y); // -- a = new ZlpFileInfo(@"C:\ablage\"); b = new FileInfo(@"C:\ablage\"); x = a.ToString(); y = b.ToString(); Assert.AreEqual(x,y); // -- a = new ZlpFileInfo(@"test.txt"); b = new FileInfo(@"test.txt"); x = a.ToString(); y = b.ToString(); Assert.AreEqual(x,y); // -- a = new ZlpFileInfo(@"c:\ablage\..\ablage\test.txt"); b = new FileInfo(@"c:\ablage\..\ablage\test.txt"); x = a.ToString(); y = b.ToString(); Assert.AreEqual(x,y); // -- a = new ZlpFileInfo(@"\ablage\test.txt"); b = new FileInfo(@"\ablage\test.txt"); x = a.ToString(); y = b.ToString(); Assert.AreEqual(x,y); // -- a = new ZlpFileInfo(@"ablage\test.txt"); b = new FileInfo(@"ablage\test.txt"); x = a.ToString(); y = b.ToString(); Assert.AreEqual(x,y); }
private static void Main(string[] args) { var f1 = new ZlpFileInfo(@"C:\Ablage\test-only\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Lalala.txt"); f1.Directory.Create(); f1.WriteAllText("lalala."); Console.WriteLine(f1.Length); new ZlpDirectoryInfo(@"C:\Ablage\test-only\").Delete(true); //f1.MoveToRecycleBin(); var f = new ZlpFileInfo(@"C:\Ablage\Lalala.txt"); f.WriteAllText("lalala."); f.MoveToRecycleBin(); var d = new ZlpDirectoryInfo(@"C:\Ablage\LalalaOrdner"); d.Create(); d.MoveToRecycleBin(); }
private AskOverwriteResult dataProcessing_CanOverwrite(ZlpFileInfo filePath) { var dr = XtraMessageBox.Show( this, string.Format(Resources.ConfirmOverwrite, filePath.Name), @"Zeta Resource Editor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { return(AskOverwriteResult.Overwrite); } else if (dr == DialogResult.No) { return(AskOverwriteResult.Skip); } else { return(AskOverwriteResult.Fail); } }
// ------------------------------------------------------------------ #endregion #region Public methods. // ------------------------------------------------------------------ /// <summary> /// Gets the <c>accessor</c> for file. /// </summary> /// <param name="filePath">The file path.</param> /// <returns>Returns NULL if none found.</returns> public static IResourceFileAccessor GetAccessorForFile( ZlpFileInfo filePath) { var all = AllAvailableResourceFileAccessors; if (all == null || all.Length <= 0) { return(null); } else { var normalizedExtension = normalizeExtension(filePath.Extension); foreach (var accessor in all) { var supportedExtensions = accessor.SupportedFileExtensions; if (supportedExtensions != null && supportedExtensions.Length > 0) { foreach (var supportedExtension in supportedExtensions) { if (normalizeExtension(supportedExtension) == normalizedExtension) { return(accessor); } } } } // Not found. return(null); } }
private AskOverwriteResult dataProcessing_CanOverwrite(ZlpFileInfo filePath) { var dr = MessageBox.Show( this, string.Format( Resources.SR_MainForm_dataProcessing_CanOverwrite_Do_you_want_to_overwrite_the_read_only_file___0___, filePath.Name), @"Zeta Resource Editor", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { return(AskOverwriteResult.Overwrite); } else if (dr == DialogResult.No) { return(AskOverwriteResult.Skip); } else { return(AskOverwriteResult.Fail); } }
public void DoAutomaticallyAddResourceFilesFromVsProject( BackgroundWorker backgroundWorker, ProjectFolder parentProjectFolder, ref int fileGroupCount, ref int fileCount, ZlpFileInfo vsProjectPath) { if (backgroundWorker.CancellationPending) { throw new OperationCanceledException(); } else if (vsProjectPath != null && vsProjectPath.Exists) { if (@".sln" == vsProjectPath.Extension.ToLowerInvariant()) { //file is solution, so add all projects from solution doAutomaticallyAddResourceFilesFromVSSolution( backgroundWorker, parentProjectFolder, ref fileGroupCount, ref fileCount, vsProjectPath); } else { //load fom solution var pdoc = new XmlDocument(); //using (var fs = vsProjectPath.OpenRead()) { pdoc.LoadXml(ZlpIOHelper.ReadAllText(vsProjectPath.FullName)); } var nameMgr = new XmlNamespaceManager(pdoc.NameTable); nameMgr.AddNamespace(@"mb", @"http://schemas.microsoft.com/developer/msbuild/2003"); //Update 16.16.2016 Christian Abele: Resourcen können unter EmbeddedResource und Content vorkommen! => Content ergänzt var xpaths = new[] { @"/mb:Project/mb:ItemGroup/mb:EmbeddedResource/@Include", @"/mb:Project/mb:ItemGroup/mb:Content/@Include" }; var resNodes = new List <XmlNode>(); foreach (var xpath in xpaths) { var r = pdoc.SelectNodes(xpath, nameMgr); if (r != null) { resNodes.AddRange(r.Cast <XmlNode>().ToArray()); } } var filePaths = new List <ZlpFileInfo>(); //get all files foreach (var node in resNodes) { var include = node.Value; if (!string.IsNullOrEmpty(include) && (include.ToLowerInvariant().EndsWith(@".resx") || include.ToLowerInvariant().EndsWith(@".resw"))) { var fullPath = ZlpPathHelper.Combine(vsProjectPath.DirectoryName, include); filePaths.Add(new ZlpFileInfo(fullPath)); } } //add all files from list DoAutomaticallyAddResourceFilesFromList( backgroundWorker, parentProjectFolder, ref fileGroupCount, ref fileCount, filePaths); } } }
private void doAutomaticallyAddResourceFilesFromVSSolution( BackgroundWorker backgroundWorker, ProjectFolder parentProjectFolder, ref int fileGroupCount, ref int fileCount, ZlpFileInfo vsSolutionPath) { if (vsSolutionPath != null && vsSolutionPath.Exists) { string solutionText; //using (var sr = vsSolutionPath.OpenText()) { //we can read it line by line to reduce memory usage, but solution files are not very big solutionText = ZlpIOHelper.ReadAllText(vsSolutionPath.FullName); // sr.ReadToEnd(); } //solution files looks like: //Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZetaResourceEditor", "Main\ZetaResourceEditor.csproj", "{367758E7-0435-440A-AC76-1F30ABBA3ED8}" //EndProject //known projectTypes: //c#: FAE04EC0-301F-11D3-BF4B-00C04F79EFBC, VB: F184B08F-C81C-45F6-A57F-5ABD9991F28F //@see http://msdn.microsoft.com/en-us/library/hb23x61k%28VS.80%29.aspx //TODO: support virtual folders var supportedProjectTypes = new[] { @"FAE04EC0-301F-11D3-BF4B-00C04F79EFBC", @"F184B08F-C81C-45F6-A57F-5ABD9991F28F" }; //we need some regular expression to find required info: const string pattern = @"Project\(""{(?<projectType>[^}]*)}""\)\s*=\s*""(?<projectName>[^""]*)"",\s*""(?<projectRelPath>[^""]*)"",\s*""{(?<projectID>[^}]*)}"""; foreach (Match m in Regex.Matches(solutionText, pattern)) { if (!m.Success) { continue; } var g = m.Groups[@"projectType"]; if (g == null || !g.Success) { continue; } var projectType = g.Value; //compare with known project types. // Currently only CS Projects are supported. // But other types like VB can be simply added. if (!Array.Exists(supportedProjectTypes, a => a == projectType)) { continue; } var projectRelPath = m.Groups[@"projectRelPath"].Value; var projectFile = new ZlpFileInfo(ZlpPathHelper.Combine(vsSolutionPath.Directory.FullName, projectRelPath)); //add all files from project //we can add each using separate sub folder var projectName = m.Groups[@"projectName"].Value; //look in subfolders only var subFolders = Project.ProjectFolders; if (parentProjectFolder != null) { subFolders = parentProjectFolder.ChildProjectFolders; } var pf = subFolders.Find(f => f.Name == projectName); if (pf == null) { pf = new ProjectFolder(Project) { Name = projectName, Parent = parentProjectFolder }; Project.ProjectFolders.Add(pf); } Project.MarkAsModified(); DoAutomaticallyAddResourceFilesFromVsProject( backgroundWorker, pf, ref fileGroupCount, ref fileCount, projectFile); } } }
public static void SafeCopy(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath, bool overwrite = true) { ZlpSafeFileOperations.SafeCopyFile(sourcePath, dstFilePath, overwrite); }
/// <summary> /// Stores a list of name/value pairs to the specified resource file. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="rows">The rows.</param> public void StoreToResourceFile( ZlpFileInfo filePath, NameValuePair[] rows) { throw new NotImplementedException(); }
public static ZlpFileInfo SafeCopy(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath, bool overwrite = true) { ZlpSafeFileOperations.SafeCopyFile(sourcePath, dstFilePath, overwrite); return sourcePath; }
public void TestGeneral() { // Ordner mit Punkt am Ende. var dir = $@"C:\Ablage\{Guid.NewGuid():N}."; Assert.IsFalse(new ZlpDirectoryInfo(dir).Exists); new ZlpDirectoryInfo(dir).CheckCreate(); Assert.IsTrue(new ZlpDirectoryInfo(dir).Exists); new ZlpDirectoryInfo(dir).Delete(true); Assert.IsFalse(new ZlpDirectoryInfo(dir).Exists); //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).CreationTime>DateTime.MinValue); //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj").Exists); //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj2").Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage").Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Exists); const string s1 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Zeta Resource Editor"; const string s2 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Web\central\Controls\App_LocalResources\ItemSearch"; var s3 = ZlpPathHelper.GetRelativePath(s1, s2); Assert.AreEqual(s3, @"..\Web\central\Controls\App_LocalResources\ItemSearch"); var ext = ZlpPathHelper.GetExtension(s3); Assert.IsEmpty(ext ?? string.Empty); ext = ZlpPathHelper.GetExtension(@"C:\Ablage\Uwe.txt"); Assert.AreEqual(ext, @".txt"); const string path = @"C:\Ablage\Test"; Assert.AreEqual( new DirectoryInfo(path).Name, new ZlpDirectoryInfo(path).Name); Assert.AreEqual( new DirectoryInfo(path).FullName, new ZlpDirectoryInfo(path).FullName); const string filePath = @"C:\Ablage\Test\file.txt"; var fn1 = new FileInfo(filePath).Directory?.FullName; var fn2 = new ZlpFileInfo(filePath).Directory.FullName; var fn1A = new FileInfo(filePath).DirectoryName; var fn2A = new ZlpFileInfo(filePath).DirectoryName; Assert.AreEqual(fn1, fn2); Assert.AreEqual(fn1A, fn2A); var fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Parent.FullName; Assert.AreEqual(fn, @"\\zetac11\C$\Ablage"); fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2\").Parent.FullName; Assert.AreEqual(fn, @"\\zetac11\C$\Ablage"); }
public void DoAutomaticallyAddResourceFilesFromVsProject( BackgroundWorker backgroundWorker, ProjectFolder parentProjectFolder, ref int fileGroupCount, ref int fileCount, ZlpFileInfo vsProjectPath) { if (backgroundWorker.CancellationPending) { throw new OperationCanceledException(); } else if (vsProjectPath != null && vsProjectPath.Exists) { if (@".sln" == vsProjectPath.Extension.ToLowerInvariant()) { //file is solution, so add all projects from solution doAutomaticallyAddResourceFilesFromVSSolution( backgroundWorker, parentProjectFolder, ref fileGroupCount, ref fileCount, vsProjectPath); } else { //load fom solution var pdoc = new XmlDocument(); //using (var fs = vsProjectPath.OpenRead()) { pdoc.LoadXml(ZlpIOHelper.ReadAllText(vsProjectPath.FullName)); } var nameMgr = new XmlNamespaceManager(pdoc.NameTable); nameMgr.AddNamespace(@"mb", @"http://schemas.microsoft.com/developer/msbuild/2003"); const string xpath = @"/mb:Project/mb:ItemGroup/mb:EmbeddedResource/@Include"; var resNodes = pdoc.SelectNodes(xpath, nameMgr); var filePaths = new List <ZlpFileInfo>(); //get all files if (resNodes != null) { // ReSharper disable LoopCanBeConvertedToQuery foreach (XmlNode node in resNodes) // ReSharper restore LoopCanBeConvertedToQuery { var include = node.Value; if (!string.IsNullOrEmpty(include) && (include.ToLowerInvariant().EndsWith(@".resx") || include.ToLowerInvariant().EndsWith(@".resw"))) { var fullPath = ZlpPathHelper.Combine(vsProjectPath.DirectoryName, include); filePaths.Add(new ZlpFileInfo(fullPath)); } } } //add all files from list DoAutomaticallyAddResourceFilesFromList( backgroundWorker, parentProjectFolder, ref fileGroupCount, ref fileCount, filePaths); } } }
public static ZlpFileInfo SafeCopy(this ZlpFileInfo sourcePath, string dstFilePath, bool overwrite = true) { ZlpSafeFileOperations.SafeCopyFile(sourcePath, dstFilePath, overwrite); return(sourcePath); }
public static ZlpFileInfo SafeMove(this ZlpFileInfo sourcePath, string dstFilePath) { ZlpSafeFileOperations.SafeMoveFile(sourcePath, dstFilePath); return(sourcePath); }
public static ZlpFileInfo SafeDelete(this ZlpFileInfo filePath) { ZlpSafeFileOperations.SafeDeleteFile(filePath); return(filePath); }
public void TestGeneral() { // Ordner mit Punkt am Ende. string dir = $@"C:\Ablage\{Guid.NewGuid():N}."; Assert.IsFalse(new ZlpDirectoryInfo(dir).Exists); new ZlpDirectoryInfo(dir).CheckCreate(); Assert.IsTrue(new ZlpDirectoryInfo(dir).Exists); new ZlpDirectoryInfo(dir).Delete(true); Assert.IsFalse(new ZlpDirectoryInfo(dir).Exists); //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).CreationTime>DateTime.MinValue); //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj").Exists); //Assert.IsTrue(new ZlpDirectoryInfo(Path.GetTempPath()).Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"C:\Ablage\doesnotexistjdlkfjsdlkfj2").Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage").Exists); //Assert.IsFalse(new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Exists); const string s1 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Zeta Resource Editor"; const string s2 = @"C:\Users\Chris\Documents\Development\ADC\InterStore.NET\Visual Studio 2008\6.4.2\Web\central\Controls\App_LocalResources\ItemSearch"; var s3 = ZlpPathHelper.GetRelativePath(s1, s2); Assert.AreEqual(s3, @"..\Web\central\Controls\App_LocalResources\ItemSearch"); var ext = ZlpPathHelper.GetExtension(s3); Assert.IsNullOrEmpty(ext); ext = ZlpPathHelper.GetExtension(@"C:\Ablage\Uwe.txt"); Assert.AreEqual(ext, @".txt"); const string path = @"C:\Ablage\Test"; Assert.AreEqual( new DirectoryInfo(path).Name, new ZlpDirectoryInfo(path).Name); Assert.AreEqual( new DirectoryInfo(path).FullName, new ZlpDirectoryInfo(path).FullName); const string filePath = @"C:\Ablage\Test\file.txt"; var fn1 = new FileInfo(filePath).Directory?.FullName; var fn2 = new ZlpFileInfo(filePath).Directory.FullName; var fn1A = new FileInfo(filePath).DirectoryName; var fn2A = new ZlpFileInfo(filePath).DirectoryName; Assert.AreEqual(fn1,fn2); Assert.AreEqual(fn1A,fn2A); var fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2").Parent.FullName; Assert.AreEqual(fn, @"\\zetac11\C$\Ablage"); fn = new ZlpDirectoryInfo(@"\\zetac11\C$\Ablage\doesnotexistjdlkfjsdlkfj2\").Parent.FullName; Assert.AreEqual(fn, @"\\zetac11\C$\Ablage"); }
private static void Main(string[] args) { const string name = @"D:\SomeStuff\Name Space\More.Stuff\Test"; var dirInfo5 = new ZlpDirectoryInfo(name); Console.WriteLine($@"'{dirInfo5.Name}'."); var dirInfo6 = new DirectoryInfo(name); Console.WriteLine($@"'{dirInfo6.Name}'."); if (dirInfo5.Name != dirInfo6.Name) { throw new Exception(@"5-6"); } // -- var dirInfo1 = new ZlpDirectoryInfo(@"C:\Foo\Bar"); Console.WriteLine(dirInfo1.Name); //"Bar" var dirInfo2 = new ZlpDirectoryInfo(@"C:\Foo\Bar\"); Console.WriteLine(dirInfo2.Name); //"", an empty string var dirInfo3 = new DirectoryInfo(@"C:\Foo\Bar"); Console.WriteLine(dirInfo1.Name); var dirInfo4 = new DirectoryInfo(@"C:\Foo\Bar\"); Console.WriteLine(dirInfo2.Name); if (dirInfo1.Name != dirInfo3.Name) { throw new Exception(@"1-3"); } if (dirInfo2.Name != dirInfo4.Name) { throw new Exception(@"2-4"); } // -- var f1 = new ZlpFileInfo( @"C:\Ablage\test-only\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Ablage\Lalala.txt"); f1.Directory.Create(); f1.WriteAllText("lalala."); Console.WriteLine(f1.Length); new ZlpDirectoryInfo(@"C:\Ablage\test-only\").Delete(true); //f1.MoveToRecycleBin(); var f = new ZlpFileInfo(@"C:\Ablage\Lalala.txt"); f.WriteAllText("lalala."); f.MoveToRecycleBin(); var d = new ZlpDirectoryInfo(@"C:\Ablage\LalalaOrdner"); d.Create(); d.MoveToRecycleBin(); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { Regex re = new Regex(@"^(?:[\w]\:|\\)(\\[a-z_\-\s0-9\.]+)*\\?$", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace); string strVal = (value ?? "").ToString().Trim(); var valid = (string.IsNullOrEmpty(strVal) || re.IsMatch(strVal)) ? new ValidationResult(true, null) : new ValidationResult(false, Properties.Resources.WrongPathFormat); // IF VALID PATH CHECK IF EXISTS if (valid.IsValid && !string.IsNullOrEmpty(strVal)) { // CHECK IF THE FILE IS IN THE CORRECT FORMAT var fileInfo = new ZlpFileInfo(strVal); if (!fileInfo.Exists) { valid = new ValidationResult(false, Properties.Resources.PathNotFound); } else // PARSE THE FILE TO CONFIRM THE EXTENSION { string ext = fileInfo.Extension.ToLower(); var bytes = fileToByteArray(strVal, 16); bool isCorrect = false; // PARSE THE BINARY TO VERIFY EXTENSION switch (ext) { case ".jpg": case ".jpeg": // JFIF or Exif or ICC isCorrect = (null == bytes) || ((0x4A == bytes[6]) && (0x46 == bytes[7]) && (0x49 == bytes[8]) && (0x46 == bytes[9])) || ((0x45 == bytes[6]) && (0x78 == bytes[7]) && (0x69 == bytes[8]) && (0x66 == bytes[9])) || ((0x49 == bytes[6]) && (0x43 == bytes[7]) && (0x43 == bytes[8])); break; case ".bmp": // BM isCorrect = (null == bytes) || ((0x42 == bytes[0]) && (0x4D == bytes[1])); break; case ".png": // PNG isCorrect = (null == bytes) || ((0x89 == bytes[0]) && (0x50 == bytes[1]) && (0x4E == bytes[2]) && (0x47 == bytes[3])); break; case ".gif": // GIF isCorrect = (null == bytes) || ((0x47 == bytes[0]) && (0x49 == bytes[1]) && (0x46 == bytes[2]) && (0x38 == bytes[3])); break; case ".tif": case ".tiff": // TIFF isCorrect = (null == bytes) || ((0x49 == bytes[0]) && (0x49 == bytes[1]) && (0x2A == bytes[2]) && (0 == bytes[3])) || ((0x4D == bytes[0]) && (0x4D == bytes[1]) && (0 == bytes[2]) && (0x2A == bytes[3])); break; default: break; } valid = isCorrect ? new ValidationResult(true, null) : new ValidationResult(false, Properties.Resources.WrongFileType); } } return(valid); }
public string GetNameIntelligent( Project project) { lock (_fileInfos) { if (string.IsNullOrEmpty(_name) && _fileInfos.Count > 0) { // Try guessing several names. var filePath = _fileInfos[0].File; var folderPath = filePath.Directory; //CHANGED: use base name instead var baseName = LanguageCodeDetection.GetBaseName(project, filePath.Name); filePath = new ZlpFileInfo(ZlpPathHelper.Combine(folderPath.FullName, baseName)); if ((string.Equals(@"Properties", folderPath.Name, StringComparison.InvariantCultureIgnoreCase) || string.Equals(@"App_GlobalResources", folderPath.Name, StringComparison.InvariantCultureIgnoreCase)) && filePath.Name.StartsWith( @"Resources.", StringComparison.InvariantCultureIgnoreCase)) { var parentFolderPath = folderPath.Parent; if (parentFolderPath == null) { return(_name); } else { //CHANGED: append fileName, otherwise name is not complete. var pathToMakeRelative = ZlpPathHelper.Combine(parentFolderPath.FullName, filePath.Name); return (shortenFilePath( ZlpPathHelper.GetRelativePath( project == null ? string.Empty : project.ProjectConfigurationFilePath.DirectoryName, pathToMakeRelative))); } } else if (string.Equals(@"App_LocalResources", folderPath.Name, StringComparison.InvariantCultureIgnoreCase)) { var name = ZlpPathHelper.GetRelativePath( project == null ? string.Empty : project.ProjectConfigurationFilePath.DirectoryName, filePath.FullName); var ext = ZlpPathHelper.GetExtension(name); var result = name.Substring(0, name.Length - ext.Length); return(shortenFilePath(result)); } else { return (shortenFilePath( ZlpPathHelper.GetRelativePath( project == null ? string.Empty : project.ProjectConfigurationFilePath.DirectoryName, filePath.FullName))); } } else { return(_name); } } }
public static ZlpFileInfo SafeMove(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath) { ZlpSafeFileOperations.SafeMoveFile(sourcePath, dstFilePath); return sourcePath; }
public bool LoadFromXml(Project project, XmlNode parentNode) { if (parentNode.Attributes != null) { XmlHelper.ReadAttribute( out _uniqueID, parentNode.Attributes[@"uniqueID"]); } if (_uniqueID == Guid.Empty) { _uniqueID = Guid.NewGuid(); } // -- string filePath = null; if (parentNode.Attributes != null) { XmlHelper.ReadAttribute( out filePath, parentNode.Attributes[@"filePath"]); } filePath = project.MakeAbsoluteFilePath(filePath); if (!string.IsNullOrEmpty(filePath) && ZlpIOHelper.FileExists(filePath)) { _file = new ZlpFileInfo(filePath); return(true); } else { // Try absolute file path if relative one fails. filePath = null; if (parentNode.Attributes != null) { XmlHelper.ReadAttribute( out filePath, parentNode.Attributes[@"absoluteFilePath"]); } if (!string.IsNullOrEmpty(filePath) && ZlpIOHelper.FileExists(filePath)) { _file = new ZlpFileInfo(filePath); return(true); } else { // Try in same folder as project file, if both above failed. filePath = null; if (parentNode.Attributes != null) { XmlHelper.ReadAttribute( out filePath, parentNode.Attributes[@"filePath"]); } if (string.IsNullOrEmpty(filePath) && parentNode.Attributes != null) { XmlHelper.ReadAttribute( out filePath, parentNode.Attributes[@"absoluteFilePath"]); } if (string.IsNullOrEmpty(filePath)) { _file = null; return(false); } else { filePath = ZlpPathHelper.GetFileNameFromFilePath(filePath); filePath = project.MakeAbsoluteFilePath(filePath); if (!string.IsNullOrEmpty(filePath) && ZlpIOHelper.FileExists(filePath)) { _file = new ZlpFileInfo(filePath); return(true); } else { _file = null; return(false); } } } } }
private bool Compare(ZlpFileInfo f, ZlpFileInfo f2, Action <long> progresscallback, int buffersize, bool shouldexist) { if (shouldexist) { for (int i = 0; i < 50; i++) { f.Refresh(); f2.Refresh(); if (f.Exists && f2.Exists) { break; } Thread.Sleep(100); } } else { f.Refresh(); f2.Refresh(); } if (!f.Exists || !f2.Exists) { return(false); } if (f.Length != f2.Length) { return(false); } byte[] buffer1 = new byte[buffersize]; byte[] buffer2 = new byte[buffersize]; byte[] buffer3 = new byte[buffersize]; byte[] buffer4 = new byte[buffersize]; using (var s = new FileStream(f.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, buffersize, FileOptions.SequentialScan)) using (var s2 = new FileStream(f2.FullName, FileMode.Open, FileAccess.Read, FileShare.Read, buffersize, FileOptions.SequentialScan)) { long total = 0; int read = buffersize; Task <bool> lastcomp = null; bool swap = false; while (read == buffersize) { if (CheckCancel()) { return(false); } swap = !swap; var b1 = s.ReadAsync(swap ? buffer1 : buffer3, 0, buffersize); var b2 = s2.ReadAsync(swap ? buffer2 : buffer4, 0, buffersize); Task.WhenAll(b1, b2).Wait(); if ((read = b1.Result) != b2.Result) { return(false); } total += read; progresscallback?.Invoke(total); lastcomp?.Wait(); if (lastcomp != null && !lastcomp.Result) { return(false); } lastcomp = ByteArrayCompareAsync(swap ? buffer1 : buffer3, swap ? buffer2 : buffer4, b1.Result); } lastcomp?.Wait(); if (lastcomp != null && !lastcomp.Result) { return(false); } } return(true); }
/// <summary> /// Loads a list of name/value pairs from the given resource file. /// </summary> /// <param name="filePath">The file path.</param> /// <returns></returns> public NameValuePair[] LoadFromResourceFile( ZlpFileInfo filePath) { throw new NotImplementedException(); }
public static void SafeDelete(this ZlpFileInfo filePath) { ZlpSafeFileOperations.SafeDeleteFile(filePath); }
public static bool SafeExists(this ZlpFileInfo filePath) { return(ZlpSafeFileOperations.SafeFileExists(filePath)); }
public static void SafeMove(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath) { ZlpSafeFileOperations.SafeMoveFile(sourcePath, dstFilePath); }
public void TestGeneral() { var tempFolder = Environment.ExpandEnvironmentVariables("%temp%"); Assert.True(ZlpIOHelper.DirectoryExists(tempFolder)); var tempPath = ZlpPathHelper.Combine(tempFolder, "ZlpTest"); try { ZlpIOHelper.CreateDirectory(tempPath); Assert.IsTrue(ZlpIOHelper.DirectoryExists(tempPath)); var filePath = ZlpPathHelper.Combine(tempPath, "text.zlp"); using (var fileHandle = ZlpIOHelper.CreateFileHandle( filePath, CreationDisposition.CreateAlways, FileAccess.GenericWrite | FileAccess.GenericRead, FileShare.None)) using (var textStream = new StreamWriter(new FileStream(fileHandle, System.IO.FileAccess.Write))) { textStream.WriteLine("Zeta Long Paths Extended testing..."); textStream.Flush(); //textStream.Close(); //fileHandle.Close(); } // -- var filePath2 = new ZlpFileInfo(ZlpPathHelper.Combine(tempPath, "text.test")); filePath2.WriteAllText(Guid.NewGuid().ToString(@"N")); var infos = new ZlpFileDateInfos { LastAccessTime = new DateTime(2010, 03, 04), LastWriteTime = new DateTime(2011, 04, 05), CreationTime = new DateTime(2012, 05, 06) }; filePath2.DateInfos = infos; var infos2 = filePath2.DateInfos; Assert.IsTrue(infos.LastAccessTime == infos2.LastAccessTime); Assert.IsTrue(infos.LastWriteTime == infos2.LastWriteTime); Assert.IsTrue(infos.CreationTime == infos2.CreationTime); // -- Assert.IsTrue(ZlpIOHelper.FileExists(filePath)); var m = ZlpIOHelper.GetFileLength(filePath); Assert.IsTrue(m > 0); Assert.IsTrue(m == new FileInfo(filePath).Length); Assert.IsTrue(ZlpIOHelper.FileExists(@"c:\Windows\notepad.exe")); Assert.IsFalse(ZlpIOHelper.FileExists(@"c:\dslfsdjklfhsd\kjsaklfjd.exe")); Assert.IsFalse(ZlpIOHelper.FileExists(@"c:\ablage")); Assert.IsFalse(ZlpIOHelper.DirectoryExists(@"c:\Windows\notepad.exe")); Assert.IsTrue(ZlpIOHelper.DirectoryExists(@"c:\Windows")); Assert.IsTrue(ZlpIOHelper.DirectoryExists(@"c:\Windows\")); Assert.IsFalse(ZlpIOHelper.DirectoryExists(@"c:\fkjhskfsdhfjkhsdjkfhsdkjfh")); Assert.IsFalse(ZlpIOHelper.DirectoryExists(@"c:\fkjhskfsdhfjkhsdjkfhsdkjfh\")); // -- Assert.DoesNotThrow(() => ZlpIOHelper.SetFileLastWriteTime(filePath, new DateTime(1986, 1, 1))); Assert.DoesNotThrow(() => ZlpIOHelper.SetFileLastAccessTime(filePath, new DateTime(1987, 1, 1))); Assert.DoesNotThrow(() => ZlpIOHelper.SetFileCreationTime(filePath, new DateTime(1988, 1, 1))); Assert.DoesNotThrow(() => ZlpIOHelper.SetFileLastWriteTime(tempPath, new DateTime(1986, 1, 1))); Assert.DoesNotThrow(() => ZlpIOHelper.SetFileLastAccessTime(tempPath, new DateTime(1987, 1, 1))); Assert.DoesNotThrow(() => ZlpIOHelper.SetFileCreationTime(tempPath, new DateTime(1988, 1, 1))); var anotherFile = ZlpPathHelper.Combine(tempPath, "test2.zpl"); ZlpIOHelper.WriteAllText(anotherFile, @"äöü."); Assert.IsTrue(ZlpIOHelper.FileExists(anotherFile)); var time = ZlpIOHelper.GetFileLastWriteTime(filePath); Assert.Greater(time, DateTime.MinValue); var owner = ZlpIOHelper.GetFileOwner(@"c:\Windows\notepad.exe"); Assert.IsNotEmpty(owner ?? string.Empty); var l = ZlpIOHelper.GetFileLength(anotherFile); Assert.IsTrue(l > 0); } finally { ZlpIOHelper.DeleteDirectory(tempPath, true); } }