@@ -31,6 +31,8 @@ This source code may use other Open Source software components (see LICENSE.txt)
31
31
using AasxPluginExportTable . Table ;
32
32
using System . Runtime . Intrinsics . X86 ;
33
33
using AnyUi ;
34
+ using System . Drawing . Drawing2D ;
35
+ using System . IO . Packaging ;
34
36
35
37
namespace AasxPluginExportTable . Smt
36
38
{
@@ -50,6 +52,10 @@ public class ExportSmt
50
52
protected StringBuilder _adoc = new StringBuilder ( ) ;
51
53
protected bool _singleFile = true ;
52
54
55
+ protected string _locationPages = "" ;
56
+ protected string _locationImages = "" ;
57
+ protected string _locationDiagrams = "" ;
58
+
53
59
protected void ProcessTextBlob ( string header , Aas . IBlob blob )
54
60
{
55
61
// any content
@@ -171,7 +177,7 @@ protected void ProcessImageLink(Aas.ISubmodelElement sme)
171
177
fn = args . fileName ;
172
178
173
179
// save absolute
174
- var absFn = Path . Combine ( _tempDir , fn ) ;
180
+ var absFn = Path . Combine ( _locationImages , fn ) ;
175
181
File . WriteAllBytes ( absFn , data ) ;
176
182
_log ? . Info ( "Image data with {0} bytes writen to {1}." , data . Length , absFn ) ;
177
183
@@ -213,7 +219,7 @@ protected void ProcessUml(Aas.IReferenceElement refel)
213
219
if ( refel . IdShort . HasContent ( ) )
214
220
pumlName = AdminShellUtil . FilterFriendlyName ( refel . IdShort ) ;
215
221
var pumlFn = pumlName + ".puml" ;
216
- var absPumlFn = Path . Combine ( _tempDir , pumlFn ) ;
222
+ var absPumlFn = Path . Combine ( _locationDiagrams , pumlFn ) ;
217
223
218
224
// make options
219
225
var umlOptions = new ExportUmlRecord ( ) ;
@@ -349,6 +355,32 @@ public void ExportSmtToFile(
349
355
_tempDir = AdminShellUtil . GetTemporaryDirectory ( ) ;
350
356
log ? . Info ( "ExportSmt: using temp directory {0} .." , _tempDir ) ;
351
357
358
+ _locationPages = _tempDir ;
359
+ _locationImages = _tempDir ;
360
+ _locationDiagrams = _tempDir ;
361
+
362
+ // sub-folders?
363
+ if ( optionsSmt . AntoraStyle )
364
+ {
365
+ try
366
+ {
367
+ _locationPages = Path . Combine ( _tempDir , "pages" ) ;
368
+ _locationImages = Path . Combine ( _tempDir , "images" ) ;
369
+ _locationDiagrams = Path . Combine ( Path . Combine ( _tempDir , "partials" ) , "diagrams" ) ;
370
+
371
+ Directory . CreateDirectory ( _locationPages ) ;
372
+ Directory . CreateDirectory ( _locationImages ) ;
373
+ Directory . CreateDirectory ( Path . Combine ( _tempDir , "partials" ) ) ;
374
+ Directory . CreateDirectory ( _locationDiagrams ) ;
375
+
376
+ _log ? . Info ( StoredPrint . Color . Black ,
377
+ "Created dedicated sub-folders for pages, images, partials/diagrams." ) ;
378
+ } catch ( Exception ex )
379
+ {
380
+ _log ? . Error ( ex , "Creating sub-folders within " + _tempDir ) ;
381
+ }
382
+ }
383
+
352
384
// predefined semantic ids
353
385
var defs = AasxPredefinedConcepts . AsciiDoc . Static ;
354
386
var mm = MatchMode . Relaxed ;
@@ -402,7 +434,7 @@ public void ExportSmtToFile(
402
434
? AdminShellUtil . FilterFriendlyName ( _srcSm . IdShort )
403
435
: "output" ;
404
436
var adocFn = title + ".adoc" ;
405
- var absAdocFn = Path . Combine ( _tempDir , adocFn ) ;
437
+ var absAdocFn = Path . Combine ( _locationPages , adocFn ) ;
406
438
407
439
// write it
408
440
File . WriteAllText ( absAdocFn , adocText ) ;
@@ -439,15 +471,27 @@ public void ExportSmtToFile(
439
471
else
440
472
{
441
473
// create zip package
474
+ #if __old_
442
475
var first = true ;
443
476
foreach ( var infn in Directory . EnumerateFiles ( _tempDir , "*" ) )
477
+ // foreach (var infn in Directory.GetFiles(_tempDir, "*", SearchOption.AllDirectories))
444
478
{
445
479
AdminShellUtil . AddFileToZip (
446
- fn , infn ,
480
+ fn ,
481
+ infn ,
447
482
fileMode : first ? FileMode . Create : FileMode . OpenOrCreate ) ;
448
483
first = false ;
449
484
}
450
- log ? . Info ( "ExportSmt: packed all files to {0}" , fn ) ;
485
+ #else
486
+ using ( Package zip = System . IO . Packaging . Package . Open ( fn , FileMode . Create ) )
487
+ {
488
+ AdminShellUtil . RecursiveAddDirToZip (
489
+ zip ,
490
+ _tempDir ) ;
491
+ }
492
+ #endif
493
+
494
+ log ? . Info ( "ExportSmt: packed all files to {0}" , fn ) ;
451
495
}
452
496
453
497
// remove temp directory
0 commit comments