Skip to content

Commit

Permalink
fix exception on deleting readonly files
Browse files Browse the repository at this point in the history
  • Loading branch information
setsumi committed Jun 19, 2022
1 parent 43c6055 commit 3b412a2
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bin
obj
.vs
*.suo
28 changes: 25 additions & 3 deletions torrentwiper/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private void button1_Click(object sender, EventArgs e)
TorrentFile torrent = Bencode.DecodeTorrentFile(torrentName);

add_info(torrent.Info["name"].ToString());
if(torrent.Info["source"] != null)
if (torrent.Info["source"] != null)
add_info(torrent.Info["source"].ToString());
add_info(torrent.Comment);
add_info(torrent.CreatedBy);
Expand Down Expand Up @@ -74,7 +74,11 @@ private void button1_Click(object sender, EventArgs e)

private void button2_Click(object sender, EventArgs e)
{
if (fileNum == 0) return; // .torrent is not loaded
if (fileNum == 0) // .torrent is not loaded
{
MessageBox.Show(".torrent file is not loaded");
return;
}

using (var fbd = new FolderBrowserDialog())
{
Expand Down Expand Up @@ -116,7 +120,25 @@ private void button3_Click(object sender, EventArgs e)
{
foreach (string file in listBoxFiles.Items)
{
File.Delete(file);
RETRY_DELETE:
try
{
FileInfo fileInfo = new FileInfo(file);
fileInfo.IsReadOnly = false;
fileInfo.Delete();
}
catch (Exception ex)
{
var res = MessageBox.Show(ex.Message, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
if (res == DialogResult.Abort)
{
break;
}
else if (res == DialogResult.Retry)
{
goto RETRY_DELETE;
}
}
}
listBoxFiles.Items.Clear();
textBox3.Text = "Junk file(s) removed";
Expand Down
4 changes: 2 additions & 2 deletions torrentwiper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
4 changes: 2 additions & 2 deletions torrentwiper/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions torrentwiper/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions torrentwiper/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
2 changes: 1 addition & 1 deletion torrentwiper/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BencodeNET" version="1.3.1" targetFramework="net40-Client" />
<package id="BencodeNET" version="1.3.1" targetFramework="net462" />
</packages>
Binary file not shown.
Binary file modified torrentwiper/packages/BencodeNET.1.3.1/BencodeNET.1.3.1.nupkg
Binary file not shown.
13 changes: 8 additions & 5 deletions torrentwiper/torrentwiper.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
Expand All @@ -10,8 +10,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>torrentwiper</RootNamespace>
<AssemblyName>torrentwiper</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
Expand All @@ -23,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand All @@ -32,11 +34,11 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="BencodeNET, Version=1.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\BencodeNET.1.3.1\lib\net40\BencodeNET.dll</HintPath>
<Private>True</Private>
<HintPath>packages\BencodeNET.1.3.1\lib\net45\BencodeNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -71,6 +73,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
Binary file removed torrentwiper/torrentwiper.suo
Binary file not shown.

0 comments on commit 3b412a2

Please sign in to comment.