ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/DecentralizedMedia/DecentralizedMediaClient/Share.cs
Revision: 527
Committed: 2005-06-25T05:16:32-07:00 (20 years ago) by douglas
File size: 2273 byte(s)
Log Message:
Fuck! Fuck! Fuck!

File Contents

# User Rev Content
1 douglas 527 // Douglas Thrift
2     //
3     // Share
4     //
5     // $Id$
6    
7     using System;
8     using System.Runtime.InteropServices;
9    
10     public class Share
11     {
12     public string path { get { return "//" + Environment.MachineName + "/" + share_; } }
13    
14     public Share(string folder)
15     {
16     folder_ = folder;
17     share_ = String.Format("DecentralizedMedia0x{0:X}$", folder.GetHashCode());
18     }
19    
20     public void Add()
21     {
22     if (!Check())
23     {
24     SHARE_INFO_2 info = new SHARE_INFO_2();
25    
26     info.shi2_netname = share_;
27     info.shi2_type = STYPE.DISKTREE;
28     info.shi2_remark = "Decentralized Media Share";
29     info.shi2_permissions = ACCESS.READ | ACCESS.EXEC;
30     info.shi2_max_uses = -1;
31     info.shi2_path = folder_;
32     info.shi2_passwd = null;
33    
34     ulong index = 0;
35    
36     // XXX: this should fucking work! but it doesn't! WTF!
37     Console.WriteLine(NetShareAdd(null, 2, info, ref index));
38     Console.WriteLine(index);
39     }
40     }
41    
42     public bool Check()
43     {
44     return false;
45     }
46    
47     public void Delete()
48     {
49     }
50    
51     enum STYPE : ulong { DISKTREE = 0, PRINTQ = 1, DEVICE = 2, IPC = 3, TEMPORARY = 0x40000000, SPECIAL = 0x80000000 }
52     [Flags]
53     enum ACCESS : ulong { READ = 0x1, WRITE = 0x2, CREATE = 0x4, EXEC = 0x8, DELETE = 0x10, ATRIB = 0x20, PERM = 0x40, ALL = READ | WRITE | CREATE | EXEC | DELETE | ATRIB | PERM }
54    
55     [StructLayout(LayoutKind.Sequential)]
56     struct SHARE_INFO_2
57     {
58     [MarshalAs(UnmanagedType.LPWStr)]
59     public string shi2_netname;
60     public STYPE shi2_type;
61     [MarshalAs(UnmanagedType.LPWStr)]
62     public string shi2_remark;
63     public ACCESS shi2_permissions;
64     public long shi2_max_uses;
65     public ulong shi2_current_uses;
66     [MarshalAs(UnmanagedType.LPWStr)]
67     public string shi2_path;
68     [MarshalAs(UnmanagedType.LPWStr)]
69     public string shi2_passwd;
70     }
71    
72     private string folder_, share_;
73    
74     [DllImport("netapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "NetShareAdd")]
75     private static extern uint NetShareAdd(string servername, ulong level, SHARE_INFO_2 buf, ref ulong parm_err);
76    
77     [DllImport("netapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "NetShareCheck")]
78     private static extern uint NetShareCheck(string servername, string device, [Out] STYPE type);
79    
80     [DllImport("netapi32.dll", CharSet = CharSet.Unicode, EntryPoint = "NetShareDel")]
81     private static extern uint NetShareDel(string servername, string netname, ulong reserved);
82     }

Properties

Name Value
svn:eol-style native
svn:keywords Id