Skip to content

Commit

Permalink
Fixed recursing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenixx19 committed Sep 13, 2023
1 parent 6a9ad6f commit 4cf2057
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 32 deletions.
4 changes: 2 additions & 2 deletions png2xnb.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Global
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Debug|x86.Build.0 = Debug|Any CPU
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Release|Any CPU.Build.0 = Release|Any CPU
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Release|x86.ActiveCfg = Release|x86
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Release|x86.Build.0 = Release|x86
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Release|x86.ActiveCfg = Release|Any CPU
{E6E83894-E69B-41E5-B6EA-4A9BFD22E8F3}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 1 addition & 2 deletions png2xnb/Models/FileWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class FileWatcher : FileSystemWatcher
public FileWatcher() : base()
{
NotifyFilter =
NotifyFilters.LastAccess |
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName;
Expand All @@ -39,7 +38,7 @@ public void Update(string path)
else
{
Path = path;
Filter = "*.*";
Filter = "*.png";
IncludeSubdirectories = true;
}

Expand Down
84 changes: 56 additions & 28 deletions png2xnb/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,47 +471,75 @@ public IEnumerable GetErrors(string propertyName)

private void OnFileChanged(object sender, FileSystemEventArgs e)
{
Debug.WriteLine("Changed: " + e.FullPath);
string relative = GetRelativePath(e.FullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
string newFile = newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb";
Debug.WriteLine("Changed: " + newFile);
try
{
//Debug.WriteLine("Changed: " + e.FullPath);
string relative = GetRelativePath(e.FullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
string newFile = newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb";
//Debug.WriteLine("Changed: " + newFile);

RunConvert(e.FullPath, newFile, Settings.Instance.IsCompressed, Settings.Instance.Format, Settings.Instance.PremultiplyAlpha);
RunConvert(e.FullPath, newFile, Settings.Instance.IsCompressed, Settings.Instance.Format, Settings.Instance.PremultiplyAlpha);
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, ex.Message);
}
}

private void OnFileCreated(object sender, FileSystemEventArgs e)
{
Debug.WriteLine("Created: " + e.FullPath);
string relative = GetRelativePath(e.FullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
Debug.WriteLine("Created: " + newfolder);

RunConvert(e.FullPath, newfolder, Settings.Instance.IsCompressed, Settings.Instance.Format, Settings.Instance.PremultiplyAlpha);
try
{
//Debug.WriteLine("Created: " + e.FullPath);
string relative = GetRelativePath(e.FullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
//Debug.WriteLine("Created: " + newfolder);

RunConvert(e.FullPath, newfolder, Settings.Instance.IsCompressed, Settings.Instance.Format, Settings.Instance.PremultiplyAlpha);
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, ex.Message);
}
}

private void OnFileDeleted(object sender, FileSystemEventArgs e)
{
Debug.WriteLine("Deleted: " + e.FullPath);
string relative = GetRelativePath(e.FullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
Debug.WriteLine("Deleted: " + newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb");

File.Delete(newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb");
try
{
//Debug.WriteLine("Deleted: " + e.FullPath);
string relative = GetRelativePath(e.FullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
//Debug.WriteLine("Deleted: " + newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb");

File.Delete(newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb");
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, ex.Message);
}
}

private void OnFileRenamed(object sender, RenamedEventArgs e)
{
Debug.WriteLine("Renamed: " + e.OldFullPath);
string relative = GetRelativePath(e.OldFullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
Debug.WriteLine("Renamed from: " + newfolder + "\\" + Path.GetFileNameWithoutExtension(e.OldFullPath) + ".xnb");
Debug.WriteLine("Renamed to: " + newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb");

File.Move(
newfolder + "\\" + Path.GetFileNameWithoutExtension(e.OldFullPath) + ".xnb",
newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb"
);
try
{
//Debug.WriteLine("Renamed: " + e.OldFullPath);
string relative = GetRelativePath(e.OldFullPath, Input);
string newfolder = Output + "\\" + Path.GetDirectoryName(relative);
//Debug.WriteLine("Renamed from: " + newfolder + "\\" + Path.GetFileNameWithoutExtension(e.OldFullPath) + ".xnb");
//Debug.WriteLine("Renamed to: " + newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb");

File.Move(
newfolder + "\\" + Path.GetFileNameWithoutExtension(e.OldFullPath) + ".xnb",
newfolder + "\\" + Path.GetFileNameWithoutExtension(e.FullPath) + ".xnb"
);
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, ex.Message);
}
}
#endregion
}
Expand Down
1 change: 1 addition & 0 deletions png2xnb/png2xnb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<LangVersion>10.0</LangVersion>
<UseWPF>true</UseWPF>
<ApplicationIcon>applicationIcon.ico</ApplicationIcon>
<PackageLicenseFile>README.md</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 4cf2057

Please sign in to comment.