|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.IO; |
|
19 |
|
20 namespace SymbianUtils.FileSystem.FilePair |
|
21 { |
|
22 public class FileNamePair |
|
23 { |
|
24 #region Constructors |
|
25 public FileNamePair() |
|
26 { |
|
27 } |
|
28 |
|
29 public FileNamePair( string aSourceName ) |
|
30 { |
|
31 iSource = aSourceName; |
|
32 } |
|
33 |
|
34 public FileNamePair( string aSourceName, string aDestinationName ) |
|
35 { |
|
36 iSource = aSourceName; |
|
37 iDestination = aDestinationName; |
|
38 } |
|
39 #endregion |
|
40 |
|
41 #region API |
|
42 public void SetCustomDestinationPath( string aFolder ) |
|
43 { |
|
44 string fileName = Path.GetFileName( Source ); |
|
45 fileName = Path.Combine( aFolder, fileName ); |
|
46 Destination = fileName; |
|
47 // |
|
48 if ( Destination.Length > 0 && ( Destination[ 0 ] == Path.AltDirectorySeparatorChar || Destination[ 0 ] == Path.DirectorySeparatorChar ) ) |
|
49 { |
|
50 Destination = Destination.Substring( 1 ); |
|
51 } |
|
52 } |
|
53 #endregion |
|
54 |
|
55 #region Properties |
|
56 public bool ProcessFile |
|
57 { |
|
58 get |
|
59 { |
|
60 bool ret = false; |
|
61 // |
|
62 if ( IsValid ) |
|
63 { |
|
64 if ( SourceExists ) |
|
65 { |
|
66 if ( !SkipIfEmptyFile || SourceFileSize > 0 ) |
|
67 { |
|
68 ret = true; |
|
69 } |
|
70 } |
|
71 } |
|
72 // |
|
73 return ret; |
|
74 } |
|
75 } |
|
76 |
|
77 public bool IsValid |
|
78 { |
|
79 get |
|
80 { |
|
81 bool sourceSet = ( Source.Length > 0 ); |
|
82 bool destinationSet = ( Destination.Length > 0 ); |
|
83 // |
|
84 return ( sourceSet && destinationSet ); |
|
85 } |
|
86 } |
|
87 |
|
88 public bool SkipIfEmptyFile |
|
89 { |
|
90 get { return iSkipIfEmptyFile; } |
|
91 set { iSkipIfEmptyFile = value; } |
|
92 } |
|
93 |
|
94 public bool SourceExists |
|
95 { |
|
96 get |
|
97 { |
|
98 bool exists = File.Exists( Source ); |
|
99 return exists; |
|
100 } |
|
101 } |
|
102 |
|
103 public bool DeleteFile |
|
104 { |
|
105 get { return iDeleteFile; } |
|
106 set { iDeleteFile = value; } |
|
107 } |
|
108 |
|
109 public string Source |
|
110 { |
|
111 get { return iSource; } |
|
112 set { iSource = value; } |
|
113 } |
|
114 |
|
115 public string Destination |
|
116 { |
|
117 get { return iDestination; } |
|
118 set { iDestination = value; } |
|
119 } |
|
120 |
|
121 public long SourceFileSize |
|
122 { |
|
123 get |
|
124 { |
|
125 long ret = 0; |
|
126 // |
|
127 try |
|
128 { |
|
129 if ( SourceExists ) |
|
130 { |
|
131 System.IO.FileInfo info = new FileInfo( Source ); |
|
132 ret = info.Length; |
|
133 } |
|
134 } |
|
135 catch( Exception ) |
|
136 { |
|
137 } |
|
138 // |
|
139 return ret; |
|
140 } |
|
141 } |
|
142 #endregion |
|
143 |
|
144 #region Data members |
|
145 private bool iDeleteFile = false; |
|
146 private bool iSkipIfEmptyFile = true; |
|
147 private string iSource = string.Empty; |
|
148 private string iDestination = string.Empty; |
|
149 #endregion |
|
150 } |
|
151 } |