- mpcv_src.zip
- Components
- FolderBrowserModel
- MPCV
- MVVM
- Powershell
- mpcv_bin.zip
- de
- System.Windows.Interactivity.resources.dll
- en
- System.Windows.Interactivity.resources.dll
- es
- System.Windows.Interactivity.resources.dll
- fr
- System.Windows.Interactivity.resources.dll
- Help
- it
- System.Windows.Interactivity.resources.dll
- ja
- System.Windows.Interactivity.resources.dll
- ko
- System.Windows.Interactivity.resources.dll
- Lobster.Components.dll
- Lobster.FolderBrowser.dll
- Lobster.MVVM.dll
- Lobster.Powershell.dll
- MPCV.exe
- System.Windows.Interactivity.dll
- System.Windows.Interactivity.xml
- zh-Hans
- System.Windows.Interactivity.resources.dll
- zh-Hant
- System.Windows.Interactivity.resources.dll
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
namespace Lobster.FolderBrowser
{
[System.ComponentModel.Composition.Export(typeof(IPathItemModel))]
public class FolderFolderModel : FolderItemModelBase
{
public FolderFolderModel()
: base(null, null)
{
}
public FolderFolderModel(string _Pathname, FolderModelConfiguration conf)
: base(_Pathname, conf)
{
}
public override void UpdateDetails()
{
Debug.Assert(Directory.Exists(pathname));
FileSize = long.MinValue; // Signals the ui the filesize will be shown as an empty string
DirectoryInfo di = new DirectoryInfo(pathname);
Attributes = di.Attributes;
CreationTime = di.CreationTime;
ChangeTime = di.LastWriteTime;
if ((configuration != null) && (configuration.CalculateFolderSizes))
{
Task t = new Task(() =>
{
var r = GetFolderSize(pathname);
long l = r.Item2 ? -r.Item1 : r.Item1;
if ((r.Item1 == 0) && (r.Item2 == true)) l = long.MaxValue;
FileSize = l;
});
t.Start();
}
}
// see http://stackoverflow.com/questions/468119/whats-the-best-way-to-calculate-the-size-of-a-directory-in-net
private static Tuple<long, bool> GetFolderSize(string folder)
{
long folderSize = 0;
bool isIncomplete = false;
try
{
if (!Directory.Exists(folder)) return new Tuple<long, bool>(0, true);
try
{
foreach (string file in Directory.GetFiles(folder))
{
if (File.Exists(file))
{
FileInfo finfo = new FileInfo(file);
folderSize += finfo.Length;
}
}
foreach (string dir in Directory.GetDirectories(folder))
{
var r = GetFolderSize(dir);
folderSize += r.Item1;
isIncomplete |= r.Item2;
}
}
catch (Exception)
{
isIncomplete = true;
}
}
catch (Exception)
{
isIncomplete = true;
}
return new Tuple<long, bool>(folderSize, isIncomplete);
}
public override string NameID { get { return "Folder"; } }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.