aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO/SharpCifs/Smb/SmbFileExtensions.cs
blob: 2ebcfa20f4e0c7516e4c6c55ae5d3c0fad9a22c6 (plain)
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SmbFileExtensions.cs implementation by J. Arturo <webmaster at komodosoft dot net>
//  
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Threading.Tasks;
using SharpCifs.Util.Sharpen;

namespace SharpCifs.Smb
{
    public static class SmbFileExtensions
    {
        /// <summary>
        /// Get file's creation date converted to local timezone
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static DateTime GetLocalCreateTime(this SmbFile smbFile)
        {
            return TimeZoneInfo.ConvertTime(Extensions.CreateDateFromUTC(smbFile.CreateTime()),
                TimeZoneInfo.Local);
        }

        /// <summary>
        /// Get file's last modified date converted to local timezone
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static DateTime GetLocalLastModified(this SmbFile smbFile)
        {
            return TimeZoneInfo.ConvertTime(Extensions.CreateDateFromUTC(smbFile.LastModified()),
                TimeZoneInfo.Local);
        }


        /// <summary>
        /// List files async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static Task<SmbFile[]> ListFilesAsync(this SmbFile smbFile)
        {
            return Task.Run(() => smbFile.ListFiles());
        }

        /// <summary>
        /// List files async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <param name="wildcard"></param>
        /// <returns></returns>
        public static Task<SmbFile[]> ListFilesAsync(this SmbFile smbFile, string wildcard)
        {
            return Task.Run(() => smbFile.ListFiles(wildcard));
        }

        /// <summary>
        /// List files async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static Task<string[]> ListAsync(this SmbFile smbFile)
        {
            return Task.Run(() => smbFile.List());
        }

        /// <summary>
        /// MkDir async method
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static Task MkDirAsync(this SmbFile smbFile)
        {
            return Task.Run(() => smbFile.Mkdir());
        }


        /// <summary>
        /// Delete file async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static Task DeleteAsync(this SmbFile smbFile)
        {
            return Task.Run(() => smbFile.Delete());
        }

        /// <summary>
        /// Rename file async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public static Task RenameToAsync(this SmbFile smbFile, SmbFile destination)
        {
            return Task.Run(() => smbFile.RenameTo(destination));
        }

        /// <summary>
        /// Get input stream async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <returns></returns>
        public static Task<InputStream> GetInputStreamAsync(this SmbFile smbFile)
        {
            return Task.Run(() => smbFile.GetInputStream());
        }


        /// <summary>
        /// Get output stream async
        /// </summary>
        /// <param name="smbFile"></param>
        /// <param name="append"></param>
        /// <returns></returns>
        public static Task<OutputStream> GetOutputStreamAsync(this SmbFile smbFile, bool append = false)
        {
            return Task.Run(() => new SmbFileOutputStream(smbFile, append) as OutputStream);
        }
    }
}