-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
224 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using System.Text; | ||
using System.Windows; | ||
|
||
namespace Niv | ||
{ | ||
class Recycle | ||
{ | ||
// Folder of recycle | ||
private static string recyclePath = Environment.CurrentDirectory + @"\Recycle\"; | ||
private DirectoryInfo di = new DirectoryInfo(recyclePath); | ||
|
||
// Id counter for every recycle files. | ||
private int recycleId = 0; | ||
|
||
// List of deleted files | ||
private List<RecycleImageInfo> recycleInfos = new List<RecycleImageInfo>(); | ||
|
||
// Get the image count in recycle list. | ||
public int count | ||
{ | ||
get | ||
{ | ||
return recycleInfos.Count; | ||
} | ||
} | ||
|
||
public Recycle() | ||
{ | ||
clean(); | ||
} | ||
|
||
// Move a image here. | ||
public void recieve(ImageInfo info, int index) | ||
{ | ||
// Create the recycle folder if not exists. | ||
di.Refresh(); | ||
if (!di.Exists) di.Create(); | ||
|
||
// Create the info | ||
RecycleImageInfo recycleInfo = new RecycleImageInfo(info, recycleId, index); | ||
|
||
// Move the file and rename it. | ||
FileInfo fi = new FileInfo(info.filename); | ||
string newName = recyclePath + recycleId + Path.GetExtension(info.filename); | ||
recycleInfo.newFilename = newName; | ||
fi.MoveTo(newName); | ||
|
||
// Record the info | ||
recycleInfos.Add(recycleInfo); | ||
|
||
recycleId++; | ||
} | ||
|
||
// Move back the last deleted image. | ||
public RecycleImageInfo undeleteLast() | ||
{ | ||
return undelete(recycleInfos.Count - 1); | ||
} | ||
|
||
// Move a image out of here, return the original index. | ||
public RecycleImageInfo undelete(int index) | ||
{ | ||
RecycleImageInfo recycleInfo = recycleInfos[index]; | ||
|
||
// Move the file back. | ||
FileInfo fi = new FileInfo(recycleInfo.newFilename); | ||
fi.MoveTo(recycleInfo.originalInfo.filename); | ||
|
||
recycleInfos.Remove(recycleInfo); | ||
|
||
return recycleInfo; | ||
} | ||
|
||
// Delete all the files in recycle and the recycle folder. | ||
public void clean() | ||
{ | ||
if (di.Exists) di.Delete(true); | ||
} | ||
|
||
// EOC | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Niv | ||
{ | ||
class RecycleImageInfo | ||
{ | ||
// The original ImageInfo, used to undelete it. | ||
public ImageInfo originalInfo; | ||
|
||
// The id(filename) in recycle folder. | ||
public int id; | ||
|
||
// The original index in the image list. Used to insert it in the original index. | ||
public int originalIndex; | ||
|
||
// New filename | ||
public string newFilename; | ||
|
||
public RecycleImageInfo(ImageInfo info, int id, int originalIndex) | ||
{ | ||
this.originalInfo = info; | ||
this.id = id; | ||
this.originalIndex = originalIndex; | ||
} | ||
|
||
// EOC | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.