|
1 /* |
|
2 * Copyright (c) 2004-2008 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 |
|
18 using System; |
|
19 using System.IO; |
|
20 using SymbianTree; |
|
21 using SymBuildParsingLib.Utils; |
|
22 using SymBuildParsingLib.Tree; |
|
23 using SymBuildParsingLib.Parser.BuildFile.Document; |
|
24 |
|
25 namespace SymBuildParsingLib.Parser.BuildFile.Nodes |
|
26 { |
|
27 public sealed class SymNodeBuildFileExport : SymNodeAddAsChild |
|
28 { |
|
29 #region Enumerations |
|
30 public enum TType |
|
31 { |
|
32 ETypeFile = 0, |
|
33 ETypeZipFile |
|
34 } |
|
35 #endregion |
|
36 |
|
37 #region Constructors & destructor |
|
38 public SymNodeBuildFileExport() |
|
39 { |
|
40 } |
|
41 |
|
42 public SymNodeBuildFileExport( TType aType ) |
|
43 { |
|
44 iType = aType; |
|
45 } |
|
46 #endregion |
|
47 |
|
48 #region API |
|
49 public TType Type |
|
50 { |
|
51 get { return iType; } |
|
52 set { iType = value; } |
|
53 } |
|
54 |
|
55 public string FileName |
|
56 { |
|
57 get { return iFileName; } |
|
58 set |
|
59 { |
|
60 if ( !( Root is SymBuildFileDocument ) ) |
|
61 { |
|
62 throw new ArgumentException( "Node must be added to tree before using this API" ); |
|
63 } |
|
64 |
|
65 // Get bld.inf file name |
|
66 SymBuildFileDocument doc = (SymBuildFileDocument) Root; |
|
67 string bldInfPath = Path.GetFullPath( doc.Context.FileName ); |
|
68 |
|
69 // Try to intepret MMP file name |
|
70 bool valid = false; |
|
71 string rootPath = Path.GetPathRoot( value ); |
|
72 bool isRooted = Path.IsPathRooted( value ); |
|
73 // |
|
74 if ( isRooted == false || rootPath == string.Empty || rootPath == @"\" ) |
|
75 { |
|
76 // If a source file is listed with a relative path, the path will be considered relative to the directory containing the bld.inf file. |
|
77 |
|
78 iFileName = SymFileSystemUtils.MergePaths( bldInfPath, value ); |
|
79 valid = true; |
|
80 } |
|
81 else if ( isRooted ) |
|
82 { |
|
83 iFileName = SymFileSystemUtils.MergePaths( SymEnvironment.RootPath, value ); |
|
84 valid = true; |
|
85 } |
|
86 |
|
87 // Throw errors if we didn't find a valid match |
|
88 if ( valid == false ) |
|
89 { |
|
90 throw new ArgumentException( "Invalid file name: " + value ); |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 public string DestinationPath |
|
96 { |
|
97 get { return iDestinationPath; } |
|
98 set |
|
99 { |
|
100 // If a destination file is not specified, the source file will be copied to epoc32\include\. |
|
101 bool valid = false; |
|
102 string rootPath = Path.GetPathRoot( value ); |
|
103 // |
|
104 if ( Path.IsPathRooted( value ) == false || rootPath == string.Empty || rootPath == @"\" ) |
|
105 { |
|
106 // If a destination file is specified with the relative path, the path will be considered relative to directory epoc32\include\. |
|
107 iDestinationPath = SymFileSystemUtils.MergePaths( SymEnvironment.Epoc32IncludePath, value ); |
|
108 valid = true; |
|
109 } |
|
110 else if ( rootPath.Length == 2 || rootPath.Length == 3 && rootPath[1] == ':' ) |
|
111 { |
|
112 // If a destination begins with a drive letter, then the file is copied to epoc32\data\<drive_letter>\<path>. For example, |
|
113 // |
|
114 // mydata.dat e:\appdata\mydata.dat |
|
115 // copies mydata.dat to epoc32\data\e\appdata\mydata.dat. |
|
116 // |
|
117 // You can use any driveletter between A and Z. |
|
118 |
|
119 string drive = rootPath[ 0 ].ToString().ToLower(); |
|
120 string pathWithoutDrive = SymFileSystemUtils.DirectoryFromPath( rootPath ); |
|
121 |
|
122 // Check drive letter is valid |
|
123 bool driveIsValid = SymFileSystemUtils.IsDriveValid( drive ); |
|
124 if ( driveIsValid ) |
|
125 { |
|
126 iDestinationPath = SymEnvironment.Epoc32DataPath + drive + pathWithoutDrive; |
|
127 valid = true; |
|
128 } |
|
129 } |
|
130 |
|
131 // Throw errors if we didn't find a valid match |
|
132 if ( valid == false ) |
|
133 { |
|
134 throw new ArgumentException( "Invalid destination path: " + value ); |
|
135 } |
|
136 } |
|
137 } |
|
138 #endregion |
|
139 |
|
140 #region Data members |
|
141 private TType iType = TType.ETypeFile; |
|
142 private string iFileName = string.Empty; |
|
143 private string iDestinationPath = SymEnvironment.Epoc32IncludePath; |
|
144 #endregion |
|
145 } |
|
146 } |