프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / MarkusImageCreate / HostAppServ.cs @ 30fe44e0

이력 | 보기 | 이력해설 | 다운로드 (8.55 KB)

1
/////////////////////////////////////////////////////////////////////////////// 
2
// Copyright (C) 2002-2019, Open Design Alliance (the "Alliance"). 
3
// All rights reserved. 
4
// 
5
// This software and its documentation and related materials are owned by 
6
// the Alliance. The software may only be incorporated into application 
7
// programs owned by members of the Alliance, subject to a signed 
8
// Membership Agreement and Supplemental Software License Agreement with the
9
// Alliance. The structure and organization of this software are the valuable  
10
// trade secrets of the Alliance and its suppliers. The software is also 
11
// protected by copyright law and international treaty provisions. Application  
12
// programs incorporating this software must include the following statement 
13
// with their copyright notices:
14
//   
15
//   This application incorporates Open Design Alliance software pursuant to a license 
16
//   agreement with Open Design Alliance.
17
//   Open Design Alliance Copyright (C) 2002-2019 by Open Design Alliance. 
18
//   All rights reserved.
19
//
20
// By use of this software, its documentation or related materials, you 
21
// acknowledge and accept the above terms.
22
///////////////////////////////////////////////////////////////////////////////
23
using System;
24
using System.Collections.Generic;
25
using System.Text;
26
using Teigha;
27
using Teigha.DatabaseServices;
28
using Microsoft.Win32;
29

    
30
namespace OdaMgdMViewApp
31
{
32
  class HostAppServ : HostApplicationServices
33
  {
34
    public HostAppServ()
35
    {
36
    }
37
       
38
    public String FindConfigPath(String configType)
39
    {
40
      String subkey = GetRegistryAcadProfilesKey();
41
      if (subkey.Length > 0)
42
      {
43
        subkey += String.Format("\\General");
44
        String searchPath;
45
        if( GetRegistryString( Registry.CurrentUser, subkey, configType, out searchPath))
46
          return searchPath;
47
      }
48
      return String.Format("");
49
    }
50

    
51
    private String FindConfigFile(String configType, String file)
52
    {
53
      String searchPath = FindConfigPath( configType );
54
      if (searchPath.Length > 0)
55
      {
56
        searchPath = String.Format("{0}\\{1}", searchPath, file);
57
        if (System.IO.File.Exists(searchPath))
58
          return searchPath;
59
      }
60
      return String.Format("");
61
    }
62

    
63
    public override String FindFile(String file, Database db, FindFileHint hint)
64
    {
65
      String sFile = this.FindFileEx(file, db, hint);
66
      if (sFile.Length > 0)
67
        return sFile;
68

    
69
      String strFileName = file;
70
      String ext;
71
      if (strFileName.Length>3)
72
        ext = strFileName.Substring(strFileName.Length - 4, 4).ToUpper();
73
      else
74
        ext = file.ToUpper();
75
      if ( ext == String.Format(".PC3") )
76
        return FindConfigFile( String.Format("PrinterConfigDir"), file);
77
      if ( ext == String.Format(".STB") || ext == String.Format(".CTB"))
78
        return FindConfigFile( String.Format("PrinterStyleSheetDir"), file);
79
      if ( ext == String.Format(".PMP"))
80
        return FindConfigFile( String.Format("PrinterDescDir"), file);
81

    
82
      switch (hint)
83
      {
84
        case FindFileHint.FontFile:
85
        case FindFileHint.CompiledShapeFile:
86
        case FindFileHint.TrueTypeFontFile:
87
        case FindFileHint.PatternFile:
88
        case FindFileHint.FontMapFile:
89
        case FindFileHint.TextureMapFile:
90
          break;
91
        default:
92
          return sFile;
93
      }
94

    
95
      if ( hint != FindFileHint.TextureMapFile && ext != String.Format(".SHX") && ext != String.Format(".PAT") && ext != String.Format(".TTF") && ext != String.Format(".TTC"))
96
      {
97
        strFileName += String.Format(".shx");
98
      }
99
      else if (hint == FindFileHint.TextureMapFile)
100
      {
101
        strFileName.Replace(String.Format("/"), String.Format("\\"));
102
        int last = strFileName.LastIndexOf("\\");
103
        if (last == -1)
104
          strFileName = "";
105
        else
106
          strFileName = strFileName.Substring(0, last);
107
      }
108

    
109

    
110
      sFile = (hint != FindFileHint.TextureMapFile) ? GetRegistryACADFromProfile() : GetRegistryAVEMAPSFromProfile();
111
      while (sFile.Length>0)
112
      {
113
        int nFindStr = sFile.IndexOf(";");
114
        String sPath;
115
        if (-1 == nFindStr)
116
        {
117
          sPath = sFile;
118
          sFile = String.Format("");
119
        }
120
        else
121
        {
122
          sPath = String.Format("{0}\\{1}", sFile.Substring(0, nFindStr), strFileName);
123
          if (System.IO.File.Exists(sPath))
124
          {
125
            return sPath;
126
          }
127
          sFile = sFile.Substring(nFindStr + 1, sFile.Length - nFindStr - 1);
128
        }
129
      }
130

    
131
      if (hint == FindFileHint.TextureMapFile)
132
      {
133
        return sFile;
134
      }
135

    
136
      if (sFile.Length <= 0)
137
      {
138
        String sAcadLocation = GetRegistryAcadLocation();
139
        if (sAcadLocation.Length > 0)
140
        {
141
          sFile = String.Format("{0}\\Fonts\\{1}", sAcadLocation, strFileName);
142
          if (System.IO.File.Exists(sFile))
143
          {
144
            sFile = String.Format("{0}\\Support\\{1}", sAcadLocation, strFileName);
145
            if (System.IO.File.Exists(sFile))
146
            {
147
              sFile = String.Format("");
148
            }
149
          }
150
        }
151
      }
152
      return sFile;
153
    }
154

    
155
    public override bool GetPassword(String fileName, PasswordOptions options, out String pass)
156
    {
157
      //PasswordDlg pwdDlg = new PasswordDlg();
158
      /*pwdDlg.TextFileName.Text = fileName;
159
      if (pwdDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
160
      {
161
        pass = pwdDlg.password.Text;
162
        return true;
163
      }*/
164
      pass = String.Format("");
165
      return false;
166
    }
167

    
168
    public override String FontMapFileName
169
    {
170
      get
171
      {
172
        String subkey = GetRegistryAcadProfilesKey();
173
        if (subkey.Length > 0)
174
        {
175
          subkey += String.Format("\\Editor Configuration");
176
          String fontMapFile;
177
          if (GetRegistryString(Registry.CurrentUser, subkey, String.Format("FontMappingFile"), out fontMapFile))
178
            return fontMapFile;
179
        }
180
        return String.Format("");
181
      }
182
    }
183

    
184
    bool GetRegistryString( RegistryKey rKey, String subkey, String name, out String value)
185
    {
186
      bool rv = false;
187
      object objData = null;
188

    
189
      RegistryKey regKey;
190
      regKey = rKey.OpenSubKey(subkey);
191
      if (regKey != null)
192
      {
193
        objData = regKey.GetValue(name);
194
        if (objData != null)
195
        {
196
          rv = true;
197
        }
198
        regKey.Close();
199
      }
200
      if (rv)
201
        value = objData.ToString();
202
      else
203
        value = String.Format("");
204

    
205
      rKey.Close();
206
      return rv;
207
    }
208

    
209
    String GetRegistryAVEMAPSFromProfile()
210
    {
211
      String subkey = GetRegistryAcadProfilesKey();
212
      if ( subkey.Length > 0 )
213
      {
214
        subkey += String.Format("\\General");
215
        // get the value for the ACAD entry in the registry
216
        String tmp;
217
        if (GetRegistryString(Registry.CurrentUser, subkey, String.Format("AVEMAPS"), out tmp))
218
          return tmp;
219
      }
220
      return String.Format("");
221
    }
222
    
223
    String GetRegistryAcadProfilesKey()
224
    {
225
      String subkey     = String.Format("SOFTWARE\\Autodesk\\AutoCAD");
226
      String tmp;
227

    
228
      if (!GetRegistryString(Registry.CurrentUser, subkey, String.Format("CurVer"), out tmp))
229
        return String.Format("");
230
      subkey += String.Format("\\{0}", tmp);
231

    
232
      if (!GetRegistryString(Registry.CurrentUser, subkey, String.Format("CurVer"), out tmp))
233
        return String.Format("");
234
      subkey += String.Format("\\{0}\\Profiles", tmp);
235

    
236
      if (!GetRegistryString(Registry.CurrentUser, subkey, String.Format(""), out tmp))
237
        return String.Format("");        
238
      subkey += String.Format("\\{0}", tmp);
239
      return subkey;
240
    }
241

    
242
    String GetRegistryAcadLocation()
243
    {
244
      String subkey     = String.Format("SOFTWARE\\Autodesk\\AutoCAD");
245
      String tmp;
246

    
247
      if (!GetRegistryString(Registry.CurrentUser, subkey, String.Format("CurVer"), out tmp))
248
        return String.Format("");
249
      subkey += String.Format("\\{0}", tmp);
250

    
251
      if (!GetRegistryString(Registry.CurrentUser, subkey, String.Format("CurVer"), out tmp))
252
        return String.Format("");
253
      subkey += String.Format("\\{0}", tmp);
254

    
255
      if (!GetRegistryString(Registry.CurrentUser, subkey, String.Format(""), out tmp))
256
        return String.Format("");        
257
      return tmp;
258
    }
259

    
260
    String GetRegistryACADFromProfile()
261
    {
262
      String subkey = GetRegistryAcadProfilesKey();
263
      if ( subkey.Length > 0 )
264
      {
265
        subkey += String.Format("\\General");
266
        // get the value for the ACAD entry in the registry
267
        String tmp;
268
        if (GetRegistryString(Registry.CurrentUser, subkey, String.Format("ACAD"), out tmp))
269
          return tmp;
270
      }
271
      return String.Format("");
272
    }
273
  };
274
}
클립보드 이미지 추가 (최대 크기: 500 MB)