// ReSharper restore SuggestBaseTypeForParameter
 public ZlpFileOrDirectoryInfo(
     // ReSharper disable SuggestBaseTypeForParameter
     ZlpFileInfo info)
 {
     _preferedType = PreferedType.File;
     _fullPath = info.FullName;
     _originalPath = info.ToString();
 }
 public static void SafeDeleteFile(
     ZlpFileInfo filePath)
 {
     if (filePath != null)
     {
         SafeDeleteFile(filePath.FullName);
     }
 }
        public DateTime GetCreationDate(string fileName)
        {
            ZlpFileInfo fileInfo = new ZlpFileInfo(fileName);
            DateTime result;

            if (fileInfo.LastWriteTime < fileInfo.CreationTime)
            {
                result = fileInfo.LastWriteTime;
            }
            else
            {
                result = fileInfo.CreationTime;
            }

            return result;
        }
예제 #4
0
        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();
        }
 public static bool SafeFileExists(
     ZlpFileInfo filePath)
 {
     return(filePath != null && SafeFileExists(filePath.FullName));
 }
예제 #6
0
 public static ZlpFileInfo ChangeExtension(
     this ZlpFileInfo o,
     string extension)
 {
     return(new ZlpFileInfo(ZlpPathHelper.ChangeExtension(o.FullName, extension)));
 }
예제 #7
0
 public static ZlpFileInfo SafeCopy(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath, bool overwrite = true)
 {
     ZlpSafeFileOperations.SafeCopyFile(sourcePath, dstFilePath, overwrite);
     return(sourcePath);
 }
 public static void SafeMoveFile(
     ZlpFileInfo sourcePath,
     ZlpFileInfo dstFilePath)
 {
     SafeMoveFile(
         sourcePath?.FullName,
         dstFilePath?.FullName);
 }
예제 #9
0
 public static ZlpFileInfo SafeDelete(this ZlpFileInfo filePath)
 {
     ZlpSafeFileOperations.SafeDeleteFile(filePath);
     return(filePath);
 }
 public int Compare(
     ZlpFileInfo b)
 {
     return(Compare(b.FullName));
 }
예제 #11
0
 public void MoveTo(ZlpFileInfo destinationFilePath)
 {
     ZlpIOHelper.MoveFile(_path, destinationFilePath.FullName);
 }
		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);
				}
			}
		}
		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);
				}
			}
		}
		private bool checkWantAddResourceFile(
			ZlpFileInfo filePath)
		{
			if (filePath == null)
			{
				return false;
			}
			else
			{
				if (string.Compare(@"Properties", filePath.Directory.Name, StringComparison.OrdinalIgnoreCase) == 0)
				{
					return true;
				}
				else
				{
					// If a "*.Designer.*" companion file exists, assume it 
					// is a Windows Forms resource file and do NOT add the file
					// since it can be translated directly from within VS.NET.

					if (Project.IgnoreWindowsFormsResourcesWithDesignerFiles)
					{
						var baseFileName =
							LanguageCodeDetection.GetBaseName(
								Project,
								filePath.Name);
						//filePath.Name.Substring(0, filePath.Name.IndexOf('.'));

						var files =
							filePath.Directory.GetFiles(
								string.Format(@"{0}.Designer.*", baseFileName));

						return files.Length <= 0;
					}
					else
					{
						return true;
					}
				}
			}
		}
예제 #15
0
        public void CopyTo(
			ZlpFileInfo destinationFilePath,
			bool overwriteExisting)
        {
            ZlpIOHelper.CopyFile(_path, destinationFilePath._path, overwriteExisting);
        }
예제 #16
0
 public void MoveTo(ZlpFileInfo destinationFilePath)
 {
     ZlpIOHelper.MoveFile(_path, destinationFilePath.FullName);
 }
예제 #17
0
 public void MoveTo(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 => ZlpIOHelper.MoveFile(FullName, destinationFilePath.FullName, overwriteExisting);
예제 #18
0
 public static ZlpFileInfo FromOther(ZlpFileInfo path)
 {
     return(new ZlpFileInfo(path));
 }
예제 #19
0
        private static void CloneDates(string sourceFilePath, string destinationFilePath)
        {
            var s = new ZlpFileInfo(sourceFilePath);
            var d = new ZlpFileInfo(destinationFilePath);

            var sc = s.CreationTime;
            var sa = s.LastAccessTime;
            var sw = s.LastWriteTime;

            if (sc > DateTime.MinValue) d.CreationTime = sc;
            if (sa > DateTime.MinValue) d.LastAccessTime = sa;
            if (sw > DateTime.MinValue) d.LastWriteTime = sw;
        }
        public string GetExtension(string fileName)
        {
            ZlpFileInfo fileInfo = new ZlpFileInfo(fileName);

            return fileInfo.Extension;
        }
예제 #21
0
 public static bool SafeExists(this ZlpFileInfo filePath)
 {
     return(ZlpSafeFileOperations.SafeFileExists(filePath));
 }
 public static int Compare(
     ZlpFileOrDirectoryInfo one,
     ZlpFileInfo two)
 {
     return(string.Compare(one.FullName.TrimEnd('\\'), two.FullName.TrimEnd('\\'), StringComparison.OrdinalIgnoreCase));
 }
 public static void SafeCopyFile(
     ZlpFileInfo sourcePath,
     ZlpFileInfo dstFilePath,
     bool overwrite = true)
 {
     SafeCopyFile(
         sourcePath?.FullName,
         dstFilePath?.FullName,
         overwrite);
 }
예제 #24
0
 public static string GetNameWithExtension(
     ZlpFileInfo path)
 {
     return(GetNameWithExtension(path.FullName));
 }
예제 #25
0
 /// <summary>
 /// Retrieves the file name with the extension in a given string.
 /// </summary>
 /// <remarks>
 /// Examples:
 /// "C:\Team\Text\Test.Txt" would return "Test.Txt".
 /// "C:\Team\Text\Test" would return "Test".
 /// </remarks>
 public static string GetNameWithExtension(
     ZlpFileInfo path)
 {
     return GetNameWithExtension(path.FullName);
 }
예제 #26
0
 public static string MakeAbsoluteTo(
     this ZlpFileInfo pathToMakeAbsolute,
     string basePathToWhichToMakeAbsoluteTo)
 {
     return(ZlpPathHelper.GetAbsolutePath(pathToMakeAbsolute.FullName, basePathToWhichToMakeAbsoluteTo));
 }
		/// <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 int Compare(
     ZlpFileOrDirectoryInfo one,
     ZlpFileInfo two)
 {
     return string.Compare(one.FullName.TrimEnd('\\'), two.FullName.TrimEnd('\\'), StringComparison.OrdinalIgnoreCase);
 }
예제 #29
0
 public static ZlpFileInfo SafeMove(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath)
 {
     ZlpSafeFileOperations.SafeMoveFile(sourcePath, dstFilePath);
     return(sourcePath);
 }
 public static bool SafeFileExists(
     ZlpFileInfo filePath)
 {
     return filePath != null && SafeFileExists(filePath.FullName);
 }
 public static int Compare(
     ZlpFileInfo one,
     string two)
 {
     return new ZlpFileOrDirectoryInfo(one).Compare(two);
 }
예제 #32
0
 public static ZlpSplittedPath SplitPath(
     ZlpFileInfo path)
 {
     return new ZlpFileOrDirectoryInfo(path).ZlpSplittedPath;
 }
 public int Compare(
     ZlpFileInfo b)
 {
     return Compare(b.FullName);
 }
		/// <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 ZlpFileOrDirectoryInfo Combine(
     ZlpFileInfo one,
     string two)
 {
     return new ZlpFileOrDirectoryInfo(one).Combine(two);
 }
예제 #36
0
 public static string MakeRelativeTo(
     this ZlpFileInfo pathToMakeRelative,
     string pathToWhichToMakeRelativeTo)
 {
     return(ZlpPathHelper.GetRelativePath(pathToWhichToMakeRelativeTo, pathToMakeRelative.FullName));
 }
 public ZlpFileOrDirectoryInfo Combine(
     ZlpFileInfo info)
 {
     return
         new ZlpFileOrDirectoryInfo(
             ZlpPathHelper.Combine(
                 EffectiveDirectory.FullName,
                 // According to Reflector, "ToString()" returns the 
                 // "OriginalPath". This is what we need here.
                 info.ToString()));
 }
예제 #38
0
 public ZlpFileInfo(ZlpFileInfo path)
 {
     FullName = path?.FullName;
 }
예제 #39
0
 public void MoveTo(ZlpFileInfo destinationFilePath)
 => ZlpIOHelper.MoveFile(FullName, destinationFilePath.FullName);
        public long GetFileSize(string fileName)
        {
            ZlpFileInfo fileInfo = new ZlpFileInfo(fileName);

            return (long)fileInfo.Length;
        }
예제 #41
0
 public void CopyToExact(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 {
     ZlpIOHelper.CopyFileExact(FullName, destinationFilePath.FullName, overwriteExisting);
 }
예제 #42
0
        public static bool EqualsNoCase(this ZlpFileInfo o, ZlpFileInfo p)
        {
            if (o == null && p == null) return true;
            else if (o == null || p == null) return false;

            return string.Equals(
                o.FullName.TrimEnd('\\', '/'),
                p.FullName.TrimEnd('\\', '/'),
                StringComparison.InvariantCultureIgnoreCase);
        }
예제 #43
0
        public static ZlpFileInfo CombineFile(this ZlpDirectoryInfo one, ZlpFileInfo two)
        {
            if (one == null) return two;
            else if (two == null) return null;

            else return new ZlpFileInfo(ZlpPathHelper.Combine(one.FullName, two.FullName));
        }
예제 #44
0
 public void CopyTo(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 {
     ZlpIOHelper.CopyFile(_path, destinationFilePath._path, overwriteExisting);
 }
예제 #45
0
        public static ZlpFileInfo CombineFile(
            this ZlpDirectoryInfo one,
            ZlpFileInfo two,
            ZlpFileInfo three,
            params ZlpFileInfo[] fours)
        {
            var result = CombineFile(one, two);
            result = CombineFile(result?.FullName, three?.FullName);

            return fours.Aggregate(result,
                (current, four) =>
                    CombineFile(current?.FullName, four?.FullName));
        }
 public static int Compare(
     ZlpFileInfo one,
     string two)
 {
     return(new ZlpFileOrDirectoryInfo(one).Compare(two));
 }
예제 #47
0
 public void MoveTo(ZlpFileInfo destinationFilePath)
     => ZlpIOHelper.MoveFile(FullName, destinationFilePath.FullName);
 public static ZlpFileOrDirectoryInfo Combine(
     ZlpFileInfo one,
     string two)
 {
     return(new ZlpFileOrDirectoryInfo(one).Combine(two));
 }
예제 #49
0
 public void CopyToExact(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 {
     ZlpIOHelper.CopyFileExact(FullName, destinationFilePath.FullName, overwriteExisting);
 }
예제 #50
0
 public static ZlpSplittedPath SplitPath(
     ZlpFileInfo path)
 {
     return(new ZlpFileOrDirectoryInfo(path).ZlpSplittedPath);
 }
예제 #51
0
		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;
			}
		}