// 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;
        }
Exemplo n.º 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));
 }
Exemplo n.º 6
0
 public static ZlpFileInfo ChangeExtension(
     this ZlpFileInfo o,
     string extension)
 {
     return(new ZlpFileInfo(ZlpPathHelper.ChangeExtension(o.FullName, extension)));
 }
Exemplo n.º 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);
 }
Exemplo n.º 9
0
 public static ZlpFileInfo SafeDelete(this ZlpFileInfo filePath)
 {
     ZlpSafeFileOperations.SafeDeleteFile(filePath);
     return(filePath);
 }
 public int Compare(
     ZlpFileInfo b)
 {
     return(Compare(b.FullName));
 }
Exemplo n.º 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;
					}
				}
			}
		}
Exemplo n.º 15
0
        public void CopyTo(
			ZlpFileInfo destinationFilePath,
			bool overwriteExisting)
        {
            ZlpIOHelper.CopyFile(_path, destinationFilePath._path, overwriteExisting);
        }
Exemplo n.º 16
0
 public void MoveTo(ZlpFileInfo destinationFilePath)
 {
     ZlpIOHelper.MoveFile(_path, destinationFilePath.FullName);
 }
Exemplo n.º 17
0
 public void MoveTo(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 => ZlpIOHelper.MoveFile(FullName, destinationFilePath.FullName, overwriteExisting);
Exemplo n.º 18
0
 public static ZlpFileInfo FromOther(ZlpFileInfo path)
 {
     return(new ZlpFileInfo(path));
 }
Exemplo n.º 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;
        }
Exemplo n.º 20
0
        public string GetExtension(string fileName)
        {
            ZlpFileInfo fileInfo = new ZlpFileInfo(fileName);

            return fileInfo.Extension;
        }
Exemplo n.º 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));
 }
Exemplo n.º 23
0
 public static void SafeCopyFile(
     ZlpFileInfo sourcePath,
     ZlpFileInfo dstFilePath,
     bool overwrite = true)
 {
     SafeCopyFile(
         sourcePath?.FullName,
         dstFilePath?.FullName,
         overwrite);
 }
Exemplo n.º 24
0
 public static string GetNameWithExtension(
     ZlpFileInfo path)
 {
     return(GetNameWithExtension(path.FullName));
 }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 29
0
 public static ZlpFileInfo SafeMove(this ZlpFileInfo sourcePath, ZlpFileInfo dstFilePath)
 {
     ZlpSafeFileOperations.SafeMoveFile(sourcePath, dstFilePath);
     return(sourcePath);
 }
Exemplo n.º 30
0
 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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()));
 }
Exemplo n.º 38
0
 public ZlpFileInfo(ZlpFileInfo path)
 {
     FullName = path?.FullName;
 }
Exemplo n.º 39
0
 public void MoveTo(ZlpFileInfo destinationFilePath)
 => ZlpIOHelper.MoveFile(FullName, destinationFilePath.FullName);
Exemplo n.º 40
0
        public long GetFileSize(string fileName)
        {
            ZlpFileInfo fileInfo = new ZlpFileInfo(fileName);

            return (long)fileInfo.Length;
        }
Exemplo n.º 41
0
 public void CopyToExact(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 {
     ZlpIOHelper.CopyFileExact(FullName, destinationFilePath.FullName, overwriteExisting);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 44
0
 public void CopyTo(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 {
     ZlpIOHelper.CopyFile(_path, destinationFilePath._path, overwriteExisting);
 }
Exemplo n.º 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));
 }
Exemplo n.º 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));
 }
Exemplo n.º 49
0
 public void CopyToExact(
     ZlpFileInfo destinationFilePath,
     bool overwriteExisting)
 {
     ZlpIOHelper.CopyFileExact(FullName, destinationFilePath.FullName, overwriteExisting);
 }
Exemplo n.º 50
0
 public static ZlpSplittedPath SplitPath(
     ZlpFileInfo path)
 {
     return(new ZlpFileOrDirectoryInfo(path).ZlpSplittedPath);
 }
Exemplo n.º 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;
			}
		}