├── explorer.jpeg
├── IpfsMount
├── FodyWeavers.xml
├── Resources
│ └── PredefineFiles
│ │ └── Manage IPFS.url
├── app.config
├── packages.config
├── PredefinedFile.cs
├── Properties
│ └── AssemblyInfo.cs
├── DokanLogger.cs
├── Program.cs
├── IpfsMount.csproj
└── IpfsDokan.cs
├── VERIFICATION.txt
├── IpfsMountTests
├── packages.config
├── IpnsDirectoryTest.cs
├── IpfsDirectoryTest.cs
├── RunnerTest.cs
├── DirectoryTest.cs
├── Properties
│ └── AssemblyInfo.cs
├── app.config
├── DriveTest.cs
├── FileTest.cs
└── IpfsMountTests.csproj
├── LICENSE.txt
├── IpfsMount.sln
├── appveyor.yml
├── IpfsMount.nuspec
├── README.md
└── .gitignore
/explorer.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/richardschneider/net-ipfs-mount/HEAD/explorer.jpeg
--------------------------------------------------------------------------------
/IpfsMount/FodyWeavers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/IpfsMount/Resources/PredefineFiles/Manage IPFS.url:
--------------------------------------------------------------------------------
1 | [InternetShortcut]
2 | URL=http://localhost:5001/webui
3 |
--------------------------------------------------------------------------------
/VERIFICATION.txt:
--------------------------------------------------------------------------------
1 | VERIFICATION
2 |
3 | Verification is intended to assist the Chocolatey moderators and community
4 | in verifying that this package's contents are trustworthy.
5 |
6 | **TODO** How to verify the package
7 |
--------------------------------------------------------------------------------
/IpfsMountTests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/IpfsMountTests/IpnsDirectoryTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Ipfs.VirtualDisk;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Ipfs.VirtualDisk.Tests
11 | {
12 | [TestClass]
13 | public class IpnsDirectoryTest
14 | {
15 |
16 | [TestMethod]
17 | public void Exists()
18 | {
19 | Assert.IsTrue(Directory.Exists("t:/ipns"));
20 | }
21 |
22 | [TestMethod]
23 | public void Has_No_Files()
24 | {
25 | var info = new DirectoryInfo("t:/ipns");
26 |
27 | Assert.IsTrue(info.Exists);
28 | Assert.AreEqual(0, info.GetFileSystemInfos("*.*").Length);
29 | }
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/IpfsMountTests/IpfsDirectoryTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Ipfs.VirtualDisk;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Ipfs.VirtualDisk.Tests
11 | {
12 | [TestClass]
13 | public class IpfsDirectoryTest
14 | {
15 |
16 | [TestMethod]
17 | public void Exists()
18 | {
19 | Assert.IsTrue(Directory.Exists("t:/ipfs"));
20 | }
21 |
22 | [TestMethod]
23 | public void Has_Pinned_Files()
24 | {
25 | var info = new DirectoryInfo("t:/ipfs");
26 |
27 | Assert.IsTrue(info.Exists);
28 | Assert.AreNotEqual(0, info.GetFileSystemInfos("*.*").Length);
29 | }
30 |
31 | }
32 | }
--------------------------------------------------------------------------------
/IpfsMount/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/IpfsMountTests/RunnerTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Ipfs.VirtualDisk;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Threading;
10 |
11 | namespace Ipfs.VirtualDisk.Tests
12 | {
13 | [TestClass]
14 | public class RunnerTest
15 | {
16 | [AssemblyInitialize]
17 | public static void Mount(TestContext context)
18 | {
19 | var vdisk = new Runner();
20 | var thread = new Thread(() => vdisk.Mount("t:", null, true));
21 | thread.Start();
22 |
23 | // Wait for Mount to work.
24 | while (true)
25 | {
26 | Thread.Sleep(0);
27 | var info = new DriveInfo("t");
28 | if (info.IsReady)
29 | break;
30 | }
31 | }
32 |
33 | [AssemblyCleanup]
34 | public static void Unmount()
35 | {
36 | var vdisk = new Runner();
37 | vdisk.Unmount("t:");
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Richard Schneider
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/IpfsMount/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/IpfsMount/PredefinedFile.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace Ipfs.VirtualDisk
10 | {
11 | class PredefinedFile
12 | {
13 | public static Dictionary All { get; private set; }
14 |
15 | static PredefinedFile()
16 | {
17 | const string prefix = "Ipfs.VirtualDisk.Resources.PredefineFiles.";
18 | All = Assembly.GetExecutingAssembly()
19 | .GetManifestResourceNames()
20 | .Where(name => name.StartsWith(prefix))
21 | .Select(name => new PredefinedFile
22 | {
23 | Name = @"\" + name.Substring(prefix.Length),
24 | Data = GetData(name)
25 | })
26 | .ToDictionary(f => f.Name, f => f);
27 | }
28 |
29 | public string Name { get; set; }
30 | public byte[] Data { get; set; }
31 |
32 | static byte[] GetData(string name)
33 | {
34 | using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
35 | using (var ms = new MemoryStream())
36 | {
37 | stream.CopyTo(ms);
38 | return ms.ToArray();
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/IpfsMountTests/DirectoryTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Ipfs.VirtualDisk;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Ipfs.VirtualDisk.Tests
11 | {
12 | [TestClass]
13 | public class DirectoryTest
14 | {
15 |
16 | [TestMethod]
17 | public void Exists()
18 | {
19 | Assert.IsTrue(Directory.Exists("t:/ipfs/QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF"));
20 | }
21 |
22 | [TestMethod]
23 | public void Directory_Info()
24 | {
25 | var info = new DirectoryInfo("t:/ipfs/QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF");
26 |
27 | Assert.IsTrue(info.Exists);
28 | Assert.AreEqual(2, info.GetFileSystemInfos("*.*").Length);
29 | }
30 |
31 | [TestMethod]
32 | public void All_Files_and_Directories()
33 | {
34 | var names = Directory.GetFileSystemEntries(@"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF", "*.*", SearchOption.AllDirectories);
35 | Assert.AreEqual(7, names.Count());
36 | CollectionAssert.Contains(names, @"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\cat.jpg");
37 | CollectionAssert.Contains(names, @"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz\f");
38 | }
39 |
40 | }
41 | }
--------------------------------------------------------------------------------
/IpfsMountTests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("IpfsMountTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("IpfsMountTests")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("07643e1d-1116-43e7-a5f5-a6bf6dd785a7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/IpfsMount/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("IpfsMount")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Richard Schneider (makaretu@gmail.com)")]
12 | [assembly: AssemblyProduct("Ifps.Net")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9a619fcc-f84b-4f8e-ac05-aabc4bdd88e4")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.42.*")]
36 | [assembly: AssemblyInformationalVersion("0.42.*-dev")]
--------------------------------------------------------------------------------
/IpfsMountTests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/IpfsMount.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.27703.2047
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IpfsMount", "IpfsMount\IpfsMount.csproj", "{9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{184C17C4-7E6D-4CB3-98A0-7CB6E5BE3F87}"
9 | ProjectSection(SolutionItems) = preProject
10 | .gitignore = .gitignore
11 | appveyor.yml = appveyor.yml
12 | IpfsMount.nuspec = IpfsMount.nuspec
13 | LICENSE.txt = LICENSE.txt
14 | README.md = README.md
15 | VERIFICATION.txt = VERIFICATION.txt
16 | EndProjectSection
17 | EndProject
18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IpfsMountTests", "IpfsMountTests\IpfsMountTests.csproj", "{07643E1D-1116-43E7-A5F5-A6BF6DD785A7}"
19 | EndProject
20 | Global
21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
22 | Debug|Any CPU = Debug|Any CPU
23 | Release|Any CPU = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
26 | {9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {07643E1D-1116-43E7-A5F5-A6BF6DD785A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31 | {07643E1D-1116-43E7-A5F5-A6BF6DD785A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
32 | {07643E1D-1116-43E7-A5F5-A6BF6DD785A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
33 | {07643E1D-1116-43E7-A5F5-A6BF6DD785A7}.Release|Any CPU.Build.0 = Release|Any CPU
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | GlobalSection(ExtensibilityGlobals) = postSolution
39 | SolutionGuid = {6CB55BA6-85ED-4F93-8376-A61168FD6C33}
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/IpfsMount/DokanLogger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Common.Logging;
7 |
8 | namespace Ipfs.VirtualDisk
9 | {
10 | ///
11 | /// Maps Dokan logging to Common Logging.
12 | ///
13 | class DokanLogger : DokanNet.Logging.ILogger
14 | {
15 | static ILog log = LogManager.GetLogger("Dokan");
16 |
17 | public void Debug(string message, params object[] args)
18 | {
19 | if (log.IsDebugEnabled)
20 | {
21 | if (args.Length > 0)
22 | log.DebugFormat(message, args);
23 | else
24 | log.Debug(message);
25 | }
26 | }
27 |
28 | public void Error(string message, params object[] args)
29 | {
30 | if (log.IsErrorEnabled)
31 | {
32 | if (args.Length > 0)
33 | log.ErrorFormat(message, args);
34 | else
35 | log.Error(message);
36 | }
37 | }
38 |
39 | public void Fatal(string message, params object[] args)
40 | {
41 | if (log.IsFatalEnabled)
42 | {
43 | if (args.Length > 0)
44 | log.FatalFormat(message, args);
45 | else
46 | log.Fatal(message);
47 | }
48 | }
49 |
50 | public void Info(string message, params object[] args)
51 | {
52 | if (log.IsInfoEnabled)
53 | {
54 | if (args.Length > 0)
55 | log.InfoFormat(message, args);
56 | else
57 | log.Info(message);
58 | }
59 | }
60 |
61 | public void Warn(string message, params object[] args)
62 | {
63 | if (log.IsWarnEnabled)
64 | {
65 | if (args.Length > 0)
66 | log.WarnFormat(message, args);
67 | else
68 | log.Warn(message);
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/IpfsMountTests/DriveTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Ipfs.VirtualDisk;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Ipfs.VirtualDisk.Tests
11 | {
12 | [TestClass]
13 | public class DriveTest
14 | {
15 | [TestMethod]
16 | public void Info()
17 | {
18 | var info = new DriveInfo("t");
19 |
20 | Assert.IsTrue(info.IsReady);
21 | Assert.AreEqual("IPFS", info.DriveFormat);
22 | Assert.AreEqual("Interplanetary", info.VolumeLabel);
23 | }
24 |
25 | [TestMethod]
26 | public void Drive_Letter_is_Case_Insensitive()
27 | {
28 | var info = new DriveInfo("T");
29 |
30 | Assert.IsTrue(info.IsReady);
31 | Assert.AreEqual("IPFS", info.DriveFormat);
32 | Assert.AreEqual("Interplanetary", info.VolumeLabel);
33 | }
34 |
35 | [TestMethod]
36 | public void Root_Exists()
37 | {
38 | var info = new DriveInfo("t").RootDirectory;
39 | Assert.IsTrue(info.Exists);
40 | Assert.AreEqual(@"t:\", info.FullName);
41 | }
42 |
43 | [TestMethod]
44 | public void Root_Contains_Special_Folders()
45 | {
46 | var info = new DriveInfo("t").RootDirectory;
47 | Assert.IsTrue(info.Exists);
48 |
49 | var folder = new DirectoryInfo("t:/ipfs");
50 | Assert.IsTrue(folder.Exists);
51 | folder = new DirectoryInfo("t:/ipns");
52 | Assert.IsTrue(folder.Exists);
53 |
54 | folder = new DirectoryInfo("t:/foobar");
55 | Assert.IsFalse(folder.Exists);
56 | }
57 |
58 | [TestMethod]
59 | public void Root_Enumerate_Special_Folders()
60 | {
61 | var folders = Directory.EnumerateDirectories("t:/");
62 | Assert.AreEqual(2, folders.Count());
63 | }
64 |
65 | [TestMethod]
66 | public void Root_has_Shortcut_to_WebUI()
67 | {
68 | const string shortcut = @"t:\Manage IPFS.url";
69 | Assert.IsTrue(File.Exists(shortcut));
70 | var lines = File.ReadAllLines(shortcut);
71 | Assert.AreEqual("[InternetShortcut]", lines[0]);
72 | }
73 |
74 | }
75 | }
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | # gitversion will change the version number
2 | version: x-{build}
3 |
4 | environment:
5 | COVERALLS_REPO_TOKEN:
6 | secure: JSfpTkHnbxXX3F54lOrfSkCbwzdQED+Ki/mjL7+2NNPfMgIFC/a4RHDgOtNX+1pW
7 | chocoKey:
8 | secure: Auc6eQGP6pNj7NMbHMQHNn7F3rTzqwQBDB1PoxDnoyxT819GKaU/Nbe3xEJYmHED
9 |
10 | # tools we need for bulding/testing/deploying
11 | install:
12 | - choco install gitversion.portable -pre -y
13 | - nuget install secure-file -ExcludeVersion
14 | - if defined snk_secret secure-file\tools\secure-file -decrypt src\ipfs.ci.snk.enc -secret %snk_secret% -out src\ipfs.dev.snk
15 | - choco install go-ipfs
16 | - ipfs init
17 | - ps: Start-Process -FilePath "ipfs.exe" -ArgumentList "daemon"
18 | # need windows update server running for dokany
19 | - ps: Set-Service wuauserv -StartupType Manual
20 | - ps: Start-Service wuauserv
21 | - cmd: choco install dokany
22 |
23 | pull_requests:
24 | do_not_increment_build_number: true
25 |
26 | # gitversion will change the assembly info
27 | assembly_info:
28 | patch: false
29 |
30 | before_build:
31 | - nuget restore
32 | - ps: gitversion /output buildserver /updateAssemblyInfo >gitversion.log
33 |
34 | platform: Any CPU
35 | configuration: Release
36 | os: Visual Studio 2017
37 |
38 | build:
39 | project: IpfsMount.sln
40 | publish_nuget: false
41 | verbosity: minimal
42 |
43 | after_build:
44 | - echo %GitVersion_NuGetVersion%
45 | - cmd: choco pack IpfsMount.nuspec -version "%GitVersion_NuGetVersion%"
46 | - cmd: appveyor PushArtifact "ipfs-mount.%GitVersion_NuGetVersion%.nupkg"
47 |
48 | after_test:
49 | # Generate coverage report
50 | - packages\OpenCover.4.6.519\tools\OpenCover.Console.exe
51 | -register:user
52 | -filter:"+[ipfs-mount]Ipfs.VirtualDisk.IpfsDokan"
53 | -target:"vstest.console.exe"
54 | -targetargs:"./IpfsMountTests/bin/Release/Ipfs.VirtualDisk.Tests.dll"
55 | -output:coverage.xml
56 | - if defined COVERALLS_REPO_TOKEN packages\coveralls.net.0.7.0\tools\csmacnz.coveralls.exe --opencover -i ./coverage.xml --serviceName appveyor --jobId %APPVEYOR_BUILD_NUMBER%
57 |
58 | deploy_script:
59 | - ps: >-
60 | if($env:APPVEYOR_REPO_BRANCH -eq 'master' -And $env:APPVEYOR_REPO_TAG -eq 'true') {
61 | $version = $env:GitVersion_NuGetVersion ;
62 | choco push ipfs-mount.$version.nupkg -k $env:chocoKey
63 | }
64 |
--------------------------------------------------------------------------------
/IpfsMount.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ipfs-mount
5 | $version$
6 | Mount IPFS
7 | Richard Schneider
8 | Richard Schneider
9 | https://github.com/richardschneider/net-ipfs-mount/issues
10 | https://github.com/richardschneider/net-ipfs-mount/blob/master/LICENSE.txt
11 | https://github.com/richardschneider/net-ipfs-mount
12 | https://github.com/richardschneider/net-ipfs-mount
13 | https://raw.githubusercontent.com/ipfs/logo/master/platform-icons/osx-menu-bar%402x.png
14 | false
15 | Mount the InterPlanetary File System as a mapped drive on Windows
16 |
17 | Mount the InterPlanetary File System as a mapped drive on Windows.
18 |
19 | See the [README](https://github.com/richardschneider/net-ipfs-mount) for details.
20 |
21 | ## Quick start
22 |
23 | > ipfs-mount z
24 | > dir z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF /B/S
25 |
26 | ````
27 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\cat.jpg
28 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test
29 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\bar
30 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz
31 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\foo
32 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz\b
33 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz\f
34 | ````
35 |
36 | © 2016-2018 Richard Schneider
37 | ipfs peer-to-peer distributed file-system
38 | View the [change log](https://github.com/richardschneider/net-ipfs-mount/releases).
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/IpfsMountTests/FileTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using Ipfs.VirtualDisk;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Ipfs.VirtualDisk.Tests
11 | {
12 | [TestClass]
13 | public class FileTest
14 | {
15 |
16 | [TestMethod]
17 | public void Exists()
18 | {
19 | Assert.IsTrue(File.Exists("t:/ipfs/QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF/cat.jpg"));
20 | Assert.IsTrue(File.Exists("t:/ipfs/QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF/test/baz/f"));
21 | Assert.IsFalse(File.Exists("t:/ipfs/QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF/test/baz/g"));
22 | }
23 |
24 | [TestMethod]
25 | public void File_Info()
26 | {
27 | var info = new FileInfo("t:/ipfs/QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF/cat.jpg");
28 |
29 | Assert.IsTrue(info.Exists);
30 | Assert.IsTrue(info.IsReadOnly);
31 | Assert.AreEqual(139781, info.Length);
32 | }
33 |
34 | [TestMethod]
35 | public void Can_Read_File()
36 | {
37 | var s = File.ReadAllText(@"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz\f");
38 | Assert.AreEqual("foo\n", s);
39 | }
40 |
41 | [TestMethod]
42 | public void Can_Read_Big_File()
43 | {
44 | var content = File.ReadAllBytes(@"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\cat.jpg");
45 | Assert.AreEqual(139781, content.Length);
46 | Assert.AreEqual(255, content[0]);
47 | Assert.AreEqual(217, content[139780]);
48 | }
49 |
50 | [TestMethod]
51 | [ExpectedException(typeof(IOException))]
52 | public void Cannot_Create_File()
53 | {
54 | File.Create(@"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\bad.file");
55 | }
56 |
57 | [TestMethod]
58 | [ExpectedException(typeof(IOException))]
59 | public void Cannot_Delete_File()
60 | {
61 | File.Create(@"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\cat.jpg");
62 | }
63 |
64 | [TestMethod]
65 | [ExpectedException(typeof(IOException))]
66 | public void Cannot_Update_File()
67 | {
68 | using (var stream = File.OpenWrite(@"t:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\cat.jpg"))
69 | {
70 | stream.Write(new byte[] { 1, 2 }, 0, 2);
71 | }
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # net-ipfs-mount
2 | [](https://ci.appveyor.com/project/richardschneider/net-ipfs-mount)
3 | [](https://coveralls.io/github/richardschneider/net-ipfs-mount?branch=master)
4 | [](https://chocolatey.org/packages/ipfs-mount)
5 |
6 | Mount the [InterPlanetary File System](https://ipfs.io/) as a mapped drive on Windows.
7 |
8 | ## Features
9 |
10 | - Mounts IPFS and IPNS on a drive letter, `ipfs-mount z:`
11 | - Unmounts the drive, `ipfs-mount z: /u`
12 | - [Pinned files](https://github.com/ipfs/examples/blob/master/examples/pinning/readme.md) are available in `z:\ipfs`
13 | - Root contains shortcut to the IPFS WebUI
14 |
15 | ## Installation
16 |
17 | [IPFS](https://ipfs.io/) and [Dokany](https://dokan-dev.github.io/) are required. If not already installed, they can be installed with [choco](https://chocolatey.org/).
18 | Installation of Dokany requires [administrator rights](http://www.howtogeek.com/194041/how-to-open-the-command-prompt-as-administrator-in-windows-8.1/).
19 |
20 | > choco install ipfs
21 | > ipfs init
22 | > choco install dokany
23 |
24 | Then install `ipfs-mount`
25 |
26 | > choco install ipfs-mount
27 |
28 | ## Quick start
29 |
30 | > ipfs-mount z
31 | > dir z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF /B/S
32 |
33 | ````
34 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\cat.jpg
35 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test
36 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\bar
37 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz
38 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\foo
39 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz\b
40 | z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF\test\baz\f
41 | ````
42 |
43 | ## Options
44 |
45 | ````
46 | Usage: ipfs-mount drive [OPTIONS]
47 | Options:
48 | -s, --server=VALUE IPFS API server address
49 | -u, --unmount Unmount the drive
50 | -d, --debug Display debugging information
51 | -h, -?, --help Show this help
52 | ````
53 |
54 | ## Example
55 |
56 | A screen shot of Windows explorer displaying the contents of `z:\ipfs\QmRCJXG7HSmprrYwDrK1GctXHgbV7EYpVcJPQPwevoQuqF`
57 |
58 | 
59 |
60 | # License
61 | Copyright © Richard Schneider (makaretu@gmail.com)
62 |
63 | The library is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form") license. Refere to the [LICENSE](https://github.com/richardschneider/net-ipfs-mount/blob/master/LICENSE.txt) file for more information.
64 |
65 |
66 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studo 2015 cache/options directory
26 | .vs/
27 |
28 | # MSTest test Results
29 | [Tt]est[Rr]esult*/
30 | [Bb]uild[Ll]og.*
31 |
32 | # NUNIT
33 | *.VisualState.xml
34 | TestResult.xml
35 |
36 | # Build Results of an ATL Project
37 | [Dd]ebugPS/
38 | [Rr]eleasePS/
39 | dlldata.c
40 |
41 | *_i.c
42 | *_p.c
43 | *_i.h
44 | *.ilk
45 | *.meta
46 | *.obj
47 | *.pch
48 | *.pdb
49 | *.pgc
50 | *.pgd
51 | *.rsp
52 | *.sbr
53 | *.tlb
54 | *.tli
55 | *.tlh
56 | *.tmp
57 | *.tmp_proj
58 | *.log
59 | *.vspscc
60 | *.vssscc
61 | .builds
62 | *.pidb
63 | *.svclog
64 | *.scc
65 |
66 | # Chutzpah Test files
67 | _Chutzpah*
68 |
69 | # Visual C++ cache files
70 | ipch/
71 | *.aps
72 | *.ncb
73 | *.opensdf
74 | *.sdf
75 | *.cachefile
76 |
77 | # Visual Studio profiler
78 | *.psess
79 | *.vsp
80 | *.vspx
81 |
82 | # TFS 2012 Local Workspace
83 | $tf/
84 |
85 | # Guidance Automation Toolkit
86 | *.gpState
87 |
88 | # ReSharper is a .NET coding add-in
89 | _ReSharper*/
90 | *.[Rr]e[Ss]harper
91 | *.DotSettings.user
92 |
93 | # JustCode is a .NET coding addin-in
94 | .JustCode
95 |
96 | # TeamCity is a build add-in
97 | _TeamCity*
98 |
99 | # DotCover is a Code Coverage Tool
100 | *.dotCover
101 |
102 | # NCrunch
103 | _NCrunch_*
104 | .*crunch*.local.xml
105 |
106 | # MightyMoose
107 | *.mm.*
108 | AutoTest.Net/
109 |
110 | # Web workbench (sass)
111 | .sass-cache/
112 |
113 | # Installshield output folder
114 | [Ee]xpress/
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish/
128 |
129 | # Publish Web Output
130 | *.[Pp]ublish.xml
131 | *.azurePubxml
132 | # TODO: Comment the next line if you want to checkin your web deploy settings
133 | # but database connection strings (with potential passwords) will be unencrypted
134 | *.pubxml
135 | *.publishproj
136 |
137 | # NuGet Packages
138 | *.nupkg
139 | # The packages folder can be ignored because of Package Restore
140 | **/packages/*
141 | # except build/, which is used as an MSBuild target.
142 | !**/packages/build/
143 | # Uncomment if necessary however generally it will be regenerated when needed
144 | #!**/packages/repositories.config
145 |
146 | # Windows Azure Build Output
147 | csx/
148 | *.build.csdef
149 |
150 | # Windows Store app package directory
151 | AppPackages/
152 |
153 | # Others
154 | *.[Cc]ache
155 | ClientBin/
156 | [Ss]tyle[Cc]op.*
157 | ~$*
158 | *~
159 | *.dbmdl
160 | *.dbproj.schemaview
161 | *.pfx
162 | *.publishsettings
163 | node_modules/
164 | bower_components/
165 |
166 | # RIA/Silverlight projects
167 | Generated_Code/
168 |
169 | # Backup & report files from converting an old project file
170 | # to a newer Visual Studio version. Backup files are not needed,
171 | # because we have git ;-)
172 | _UpgradeReport_Files/
173 | Backup*/
174 | UpgradeLog*.XML
175 | UpgradeLog*.htm
176 |
177 | # SQL Server files
178 | *.mdf
179 | *.ldf
180 |
181 | # Business Intelligence projects
182 | *.rdl.data
183 | *.bim.layout
184 | *.bim_*.settings
185 |
186 | # Microsoft Fakes
187 | FakesAssemblies/
188 |
189 | # Node.js Tools for Visual Studio
190 | .ntvs_analysis.dat
191 |
192 | # Visual Studio 6 build log
193 | *.plg
194 |
195 | # Visual Studio 6 workspace options file
196 | *.opt
197 |
--------------------------------------------------------------------------------
/IpfsMount/Program.cs:
--------------------------------------------------------------------------------
1 | using Common.Logging;
2 | using Common.Logging.Configuration;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using DokanNet;
9 | using Ipfs.Api;
10 | using NDesk.Options;
11 |
12 | namespace Ipfs.VirtualDisk
13 | {
14 | class Program
15 | {
16 | static int Main(string[] args)
17 | {
18 | // Command line parsing
19 | bool help = false;
20 | bool debugging = false;
21 | bool unmount = false;
22 | string apiUrl = "http://127.0.0.1:5001";
23 | var p = new OptionSet() {
24 | { "s|server=", "IPFS API server address", v => apiUrl = v},
25 | { "u|unmount", "Unmount the drive", v => unmount = v != null },
26 | { "d|debug", "Display debugging information", v => debugging = v != null },
27 | { "h|?|help", "Show this help", v => help = v != null },
28 | };
29 | List extras;
30 | try
31 | {
32 | extras = p.Parse(args);
33 | }
34 | catch (OptionException e)
35 | {
36 | return ShowError(e.Message);
37 | }
38 | if (help)
39 | return ShowHelp(p);
40 |
41 | // Logging
42 | NameValueCollection properties = new NameValueCollection();
43 | properties["level"] = debugging ? "Debug" : "Error";
44 | properties["showDateTime"] = debugging.ToString();
45 | LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter(properties);
46 | var log = LogManager.GetLogger("ipfs-mount");
47 |
48 | // Allow colon after drive letter
49 | if (extras.Count < 1)
50 | return ShowError("Missing the drive letter.");
51 | else if (extras.Count > 1)
52 | return ShowError("Unknown option");
53 |
54 | var drive = extras[0];
55 | if (drive.EndsWith(":"))
56 | drive = drive.Substring(0, drive.Length - 1);
57 | drive = drive + @":\";
58 |
59 | // Do the command
60 | var program = new Runner();
61 | try
62 | {
63 | if (unmount)
64 | program.Unmount(drive);
65 | else
66 | program.Mount(drive, apiUrl, debugging);
67 | }
68 | catch (Exception e)
69 | {
70 | if (debugging)
71 | log.Fatal("Failed", e);
72 |
73 | return ShowError(e);
74 | }
75 |
76 | return 0;
77 | }
78 |
79 | static int ShowError(string message)
80 | {
81 | Console.WriteLine(message);
82 | Console.WriteLine("Try 'ipfs-mount --help' for more information.");
83 | return 1;
84 | }
85 |
86 | static int ShowError(Exception ex)
87 | {
88 | for (var e = ex; e != null; e = e.InnerException)
89 | {
90 | Console.WriteLine(e.Message);
91 | }
92 |
93 | return 1;
94 | }
95 |
96 | static int ShowHelp(OptionSet p)
97 | {
98 | Console.WriteLine("Mount the IPFS on the specified drive");
99 | Console.WriteLine();
100 | Console.WriteLine("Usage: ipfs-mount drive [OPTIONS]");
101 | Console.WriteLine("Options:");
102 | p.WriteOptionDescriptions(Console.Out);
103 | return 0;
104 | }
105 | }
106 |
107 | public class Runner
108 | {
109 | public void Mount(string drive, string apiUrl, bool debugging)
110 | {
111 | if (apiUrl != null && apiUrl.Length > 0)
112 | IpfsClient.DefaultApiUri = new Uri(apiUrl);
113 |
114 | // Verify that the local IPFS service is up and running
115 | var x = new IpfsClient().IdAsync().Result;
116 |
117 | // CTRL-C will dismount and then exit.
118 | Console.CancelKeyPress += (s, e) =>
119 | {
120 | Console.WriteLine("shutting down...");
121 | Unmount(drive);
122 | e.Cancel = true;
123 | };
124 |
125 | // Mount IPFS, doesn't return until the drive is dismounted
126 | var options = DokanOptions.WriteProtection;
127 | if (debugging)
128 | options |= DokanOptions.DebugMode;
129 | Dokan.Mount(new IpfsDokan(), drive, options, new DokanLogger());
130 | }
131 |
132 | public void Unmount(string drive)
133 | {
134 | Dokan.Unmount(drive[0]);
135 | }
136 | }
137 |
138 | }
139 |
--------------------------------------------------------------------------------
/IpfsMountTests/IpfsMountTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {07643E1D-1116-43E7-A5F5-A6BF6DD785A7}
7 | Library
8 | Properties
9 | Ipfs.VirtualDisk.Tests
10 | Ipfs.VirtualDisk.Tests
11 | v4.5.2
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 10.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 |
21 |
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 |
30 |
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | {9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}
65 | IpfsMount
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | False
77 |
78 |
79 | False
80 |
81 |
82 | False
83 |
84 |
85 | False
86 |
87 |
88 |
89 |
90 |
91 |
92 |
99 |
--------------------------------------------------------------------------------
/IpfsMount/IpfsMount.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {9A619FCC-F84B-4F8E-AC05-AABC4BDD88E4}
8 | Exe
9 | Properties
10 | Ipfs.VirtualDisk
11 | ipfs-mount
12 | v4.5.2
13 | 512
14 | true
15 |
16 |
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 | ..\packages\Portable.BouncyCastle.1.8.2\lib\net40\BouncyCastle.Crypto.dll
40 |
41 |
42 | ..\packages\Common.Logging.3.4.1\lib\net40\Common.Logging.dll
43 |
44 |
45 | ..\packages\Common.Logging.Core.3.4.1\lib\net40\Common.Logging.Core.dll
46 |
47 |
48 | ..\packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll
49 | False
50 |
51 |
52 | ..\packages\DokanNet.1.1.2\lib\net40\DokanNet.dll
53 |
54 |
55 | ..\packages\Google.Protobuf.3.6.0\lib\net45\Google.Protobuf.dll
56 |
57 |
58 | ..\packages\Ipfs.Api.0.22.1\lib\net45\Ipfs.Api.dll
59 |
60 |
61 | ..\packages\Ipfs.Core.0.29.1\lib\net45\Ipfs.Core.dll
62 |
63 |
64 | ..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll
65 | True
66 |
67 |
68 | ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll
69 |
70 |
71 | ..\packages\SimpleBase.1.3.1\lib\net45\SimpleBase.dll
72 |
73 |
74 | ..\packages\StringInterpolationBridgeStrong.0.9.1\lib\net40\StringInterpolationBridge.dll
75 | True
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | Designer
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 | ();
121 | var attribute = config.Attribute("ExcludeAssemblies");
122 | if (attribute != null)
123 | foreach (var item in attribute.Value.Split('|').Select(x => x.Trim()).Where(x => x != string.Empty))
124 | excludedAssemblies.Add(item);
125 | var element = config.Element("ExcludeAssemblies");
126 | if (element != null)
127 | foreach (var item in element.Value.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).Where(x => x != string.Empty))
128 | excludedAssemblies.Add(item);
129 |
130 | var filesToCleanup = Files.Select(f => f.ItemSpec).Where(f => !excludedAssemblies.Contains(Path.GetFileNameWithoutExtension(f), StringComparer.InvariantCultureIgnoreCase));
131 |
132 | foreach (var item in filesToCleanup)
133 | File.Delete(item);
134 | ]]>
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
144 |
145 |
146 |
147 |
148 |
149 |
156 |
--------------------------------------------------------------------------------
/IpfsMount/IpfsDokan.cs:
--------------------------------------------------------------------------------
1 | using DokanNet;
2 | using Ipfs.Api;
3 | using IpfsFile = Ipfs.IFileSystemNode;
4 | using Newtonsoft.Json;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.IO;
11 | using System.Security.AccessControl;
12 | using Newtonsoft.Json.Linq;
13 | using System.Security.Principal;
14 |
15 | namespace Ipfs.VirtualDisk
16 | {
17 | ///
18 | /// Maps Dokan opeations into IPFS.
19 | ///
20 | partial class IpfsDokan : IDokanOperations
21 | {
22 | const string rootName = @"\";
23 | static string[] rootFolders = { "ipfs", "ipns" };
24 | static IpfsClient ipfs = new IpfsClient();
25 | static FileSecurity readonlyFileSecurity = new FileSecurity();
26 | static DirectorySecurity readonlyDirectorySecurity = new DirectorySecurity();
27 |
28 | static IpfsDokan()
29 | {
30 | var everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
31 | var everyoneRead = new FileSystemAccessRule(everyone,
32 | FileSystemRights.ReadAndExecute | FileSystemRights.ListDirectory,
33 | AccessControlType.Allow);
34 | readonlyFileSecurity.AddAccessRule(everyoneRead);
35 | readonlyFileSecurity.SetOwner(everyone);
36 | readonlyFileSecurity.SetGroup(everyone);
37 | readonlyDirectorySecurity.AddAccessRule(everyoneRead);
38 | readonlyDirectorySecurity.SetOwner(everyone);
39 | readonlyDirectorySecurity.SetGroup(everyone);
40 | }
41 |
42 | public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
43 | {
44 | // Read only access.
45 | if (mode != FileMode.Open || (access & DokanNet.FileAccess.WriteData) != 0)
46 | return DokanResult.AccessDenied;
47 |
48 | // Root and root folders are always present.
49 | if (fileName == rootName || rootFolders.Any(name => fileName == (rootName + name)))
50 | {
51 | info.IsDirectory = true;
52 | return DokanResult.Success;
53 | }
54 |
55 | // Predefined files
56 | PredefinedFile predefinedFile = null;
57 | if (PredefinedFile.All.TryGetValue(fileName, out predefinedFile))
58 | {
59 | info.Context = predefinedFile;
60 | return DokanResult.Success;
61 | }
62 |
63 | // Get file info from IPFS
64 | var ipfsFileName = fileName.Replace(@"\", "/");
65 | try
66 | {
67 | var file = GetIpfsFile(ipfsFileName);
68 | info.Context = file;
69 | info.IsDirectory = file.IsDirectory;
70 | }
71 | catch
72 | {
73 | return DokanResult.FileNotFound;
74 | }
75 |
76 | return DokanResult.Success;
77 | }
78 |
79 | IpfsFile GetIpfsFile(string name)
80 | {
81 | return ipfs.FileSystem.ListFileAsync(name).Result;
82 | }
83 | public NtStatus GetFileInformation(string fileName, out FileInformation fileInfo, DokanFileInfo info)
84 | {
85 | fileInfo = new FileInformation {
86 | FileName = fileName,
87 | Attributes = FileAttributes.ReadOnly
88 | };
89 | var file = info.Context as IpfsFile;
90 | if (file != null)
91 | {
92 | if (file.IsDirectory)
93 | fileInfo.Attributes |= FileAttributes.Directory;
94 | fileInfo.Length = file.Size;
95 |
96 | return DokanResult.Success;
97 | }
98 |
99 | var predefinedFile = info.Context as PredefinedFile;
100 | if (predefinedFile != null)
101 | {
102 | fileInfo.Length = predefinedFile.Data.Length;
103 | return DokanResult.Success;
104 | }
105 |
106 | // Root info
107 | if (fileName == rootName)
108 | {
109 | fileInfo.Attributes |= FileAttributes.Directory;
110 | fileInfo.LastAccessTime = DateTime.Now;
111 |
112 | return DokanResult.Success;
113 | }
114 |
115 | // Root folder info
116 | if (rootFolders.Any(name => fileName == (rootName + name)))
117 | {
118 | fileInfo.Attributes |= FileAttributes.Directory;
119 | fileInfo.LastAccessTime = DateTime.Now;
120 |
121 | return DokanResult.Success;
122 | }
123 |
124 | return DokanResult.FileNotFound;
125 | }
126 |
127 | public NtStatus GetFileSecurity(string fileName, out FileSystemSecurity security, AccessControlSections sections, DokanFileInfo info)
128 | {
129 | security = info.IsDirectory
130 | ? (FileSystemSecurity) readonlyDirectorySecurity
131 | : readonlyFileSecurity;
132 | return DokanResult.Success;
133 | }
134 |
135 | #region Volumne Operations
136 | public NtStatus GetDiskFreeSpace(out long freeBytesAvailable, out long totalNumberOfBytes, out long totalNumberOfFreeBytes, DokanFileInfo info)
137 | {
138 | freeBytesAvailable = 0;
139 | totalNumberOfBytes = 0;
140 | totalNumberOfFreeBytes = 0;
141 |
142 | return NtStatus.Success;
143 | }
144 |
145 | public NtStatus GetVolumeInformation(
146 | out string volumeLabel,
147 | out FileSystemFeatures features,
148 | out string fileSystemName,
149 | out uint maximumComponentLength,
150 | DokanFileInfo info)
151 | {
152 | volumeLabel = "Interplanetary";
153 | features = FileSystemFeatures.ReadOnlyVolume
154 | | FileSystemFeatures.CasePreservedNames | FileSystemFeatures.CaseSensitiveSearch
155 | | FileSystemFeatures.PersistentAcls | FileSystemFeatures.SupportsRemoteStorage
156 | | FileSystemFeatures.UnicodeOnDisk | FileSystemFeatures.SupportsObjectIDs;
157 | fileSystemName = "IPFS";
158 | info.IsDirectory = true;
159 | maximumComponentLength = 255;
160 |
161 | return NtStatus.Success;
162 | }
163 |
164 | public NtStatus Mounted(DokanFileInfo info)
165 | {
166 | Console.WriteLine("IPFS mounted");
167 | return NtStatus.Success;
168 | }
169 |
170 | public NtStatus Unmounted(DokanFileInfo info)
171 | {
172 | Console.WriteLine("IPFS unmounted");
173 | return NtStatus.Success;
174 | }
175 |
176 | #endregion
177 |
178 | #region File Operations
179 | public NtStatus ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info)
180 | {
181 | var predefinedFile = info.Context as PredefinedFile;
182 | if (predefinedFile != null)
183 | {
184 | bytesRead = (int) Math.Min(buffer.LongLength, predefinedFile.Data.LongLength - offset);
185 | Buffer.BlockCopy(predefinedFile.Data, (int)offset, buffer, 0, bytesRead);
186 | return DokanResult.Success;
187 | }
188 |
189 |
190 | var file = (IpfsFile)info.Context;
191 |
192 | using (var data = ipfs.FileSystem.ReadFileAsync(file.Id, offset, buffer.LongLength).Result)
193 | {
194 | // Fill the entire buffer
195 | bytesRead = 0;
196 | int bufferOffset = 0;
197 | int remainingBytes = buffer.Length;
198 | while (remainingBytes > 0)
199 | {
200 | int n = data.Read(buffer, bufferOffset, remainingBytes);
201 | if (n < 1)
202 | break;
203 | bufferOffset += n;
204 | remainingBytes -= n;
205 | bytesRead += n;
206 | }
207 | return DokanResult.Success;
208 | }
209 | }
210 |
211 | public NtStatus LockFile(string fileName, long offset, long length, DokanFileInfo info)
212 | {
213 | return DokanResult.Success; // LockFile does nothing
214 | }
215 |
216 | public NtStatus UnlockFile(string fileName, long offset, long length, DokanFileInfo info)
217 | {
218 | return DokanResult.Success; // UnlockFile does nothing
219 | }
220 |
221 | public NtStatus WriteFile(string fileName, byte[] buffer, out int bytesWritten, long offset, DokanFileInfo info)
222 | {
223 | bytesWritten = 0;
224 | return DokanResult.AccessDenied;
225 | }
226 |
227 | public NtStatus DeleteFile(string fileName, DokanFileInfo info)
228 | {
229 | return DokanResult.AccessDenied;
230 | }
231 |
232 | public NtStatus MoveFile(string oldName, string newName, bool replace, DokanFileInfo info)
233 | {
234 | return DokanResult.AccessDenied;
235 | }
236 |
237 | public NtStatus SetAllocationSize(string fileName, long length, DokanFileInfo info)
238 | {
239 | return DokanResult.AccessDenied;
240 | }
241 |
242 | public NtStatus SetEndOfFile(string fileName, long length, DokanFileInfo info)
243 | {
244 | return DokanResult.AccessDenied;
245 | }
246 |
247 | public NtStatus SetFileAttributes(string fileName, FileAttributes attributes, DokanFileInfo info)
248 | {
249 | return DokanResult.AccessDenied;
250 | }
251 |
252 | public NtStatus SetFileSecurity(string fileName, FileSystemSecurity security, AccessControlSections sections, DokanFileInfo info)
253 | {
254 | return DokanResult.AccessDenied;
255 | }
256 |
257 | public NtStatus SetFileTime(string fileName, DateTime? creationTime, DateTime? lastAccessTime, DateTime? lastWriteTime, DokanFileInfo info)
258 | {
259 | return DokanResult.AccessDenied;
260 | }
261 | #endregion
262 |
263 | #region Directory Operations
264 | public NtStatus FindFiles(string fileName, out IList files, DokanFileInfo info)
265 | {
266 | var file = info.Context as IpfsFile;
267 | if (file != null)
268 | {
269 | files = file.Links
270 | .Select(link => new FileInformation()
271 | {
272 | FileName = link.Name,
273 | Length = link.Size,
274 | Attributes = FileAttributes.ReadOnly
275 | | (link.IsDirectory ? FileAttributes.Directory : FileAttributes.Normal)
276 | })
277 | .ToList();
278 | return DokanResult.Success;
279 | }
280 |
281 | // '/ipfs' contains the pinned files.
282 | if (fileName == @"\ipfs")
283 | {
284 | var cids = ipfs.Pin.ListAsync().Result;
285 | files = cids
286 | .Select(cid =>
287 | {
288 | try
289 | {
290 | return GetIpfsFile(cid);
291 | }
292 | catch
293 | {
294 | return null;
295 | }
296 | })
297 | .Where(f => f != null)
298 | .Select(pinnedFile => new FileInformation
299 | {
300 | FileName = pinnedFile.Id,
301 | Length = pinnedFile.Size,
302 | Attributes = FileAttributes.ReadOnly
303 | | (pinnedFile.IsDirectory ? FileAttributes.Directory : FileAttributes.Normal)
304 | })
305 | .ToList();
306 | return DokanResult.Success;
307 | }
308 |
309 | // The root consists of the root folders and the predefined files.
310 | if (fileName == rootName)
311 | {
312 | files = rootFolders
313 | .Select(name => new FileInformation
314 | {
315 | FileName = name,
316 | Attributes = FileAttributes.Directory | FileAttributes.ReadOnly,
317 | LastAccessTime = DateTime.Now
318 | })
319 | .ToList();
320 | foreach (var predefinedFile in PredefinedFile.All.Values)
321 | {
322 | files.Add(new FileInformation
323 | {
324 | FileName = Path.GetFileName(predefinedFile.Name),
325 | Attributes = FileAttributes.ReadOnly,
326 | Length = predefinedFile.Data.Length
327 | });
328 | }
329 | return DokanResult.Success;
330 | }
331 |
332 | // Can not determine the contents of the root folders.
333 | if (rootFolders.Any(name => fileName == (rootName + name)))
334 | {
335 | files = new FileInformation[0];
336 | return DokanResult.Success;
337 | }
338 |
339 | files = new FileInformation[0];
340 | return DokanResult.Success;
341 | }
342 |
343 | public NtStatus FindFilesWithPattern(string fileName, string searchPattern, out IList files, DokanFileInfo info)
344 | {
345 | files = new FileInformation[0];
346 | return DokanResult.NotImplemented;
347 | }
348 |
349 | public NtStatus DeleteDirectory(string fileName, DokanFileInfo info)
350 | {
351 | return DokanResult.AccessDenied;
352 | }
353 |
354 | #endregion
355 |
356 | #region Misc Operations
357 | public void Cleanup(string fileName, DokanFileInfo info)
358 | {
359 | // Nothing to do.
360 | }
361 |
362 | public void CloseFile(string fileName, DokanFileInfo info)
363 | {
364 | // Nothing to do.
365 | }
366 |
367 | public NtStatus FindStreams(string fileName, out IList streams, DokanFileInfo info)
368 | {
369 | streams = null;
370 | return DokanResult.NotImplemented;
371 | }
372 |
373 | public NtStatus FlushFileBuffers(string fileName, DokanFileInfo info)
374 | {
375 | return DokanResult.Success;
376 | }
377 |
378 | #endregion
379 |
380 | }
381 | }
382 |
383 |
384 |
--------------------------------------------------------------------------------