-
Notifications
You must be signed in to change notification settings - Fork 0
/
StyleConverterApplication.cpp
122 lines (109 loc) · 3.34 KB
/
StyleConverterApplication.cpp
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
//---------------------------------------------------------------------------
#pragma hdrstop
#include "StyleConverterApplication.h"
#include <System.Classes.hpp>
#include <FMX.Styles.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
/**
* Callback for supported platform.
* @param APlatformTarget The platform target to validate. This is not used.
* @return Always return true.
*/
bool __fastcall SupportedPlatformHook(const System::UnicodeString APlatformTarget)
{
return true;
}
/**
* Constructor.
*/
__fastcall TStyleConverterApplication::TStyleConverterApplication() :
System::TObject()
{
}
/**
* Destructor.
*/
__fastcall TStyleConverterApplication::~TStyleConverterApplication()
{
}
/**
* Run.
*/
void __fastcall TStyleConverterApplication::Run()
{
if(ParamCount() < 1)
{
String Usage = "Copyright (c) 2014-2021 Crayon Application";
Usage += "\nUsage: StyleConverter.exe file [-f format]";
Usage += "\nfile\tstyle file to convert";
Usage += "\n -f\tformat: 0=Indexed, 1=Binary, 2=Text";
//Usage += "\n -o\toutput to file";
throw(Exception(Usage));
}
// This must be called before loading the style
Fmx::Styles::TStyleStreaming::SetSupportedPlatformHook(SupportedPlatformHook);
String LOutputFileName;
const String LInputFileName = ParamStr(1);
TStyleFormat LStyleFormat = TStyleFormat::Binary; // Default value
String LFormatString;
if(FindCmdLineSwitch("f", LFormatString) == true)
{
try
{
LStyleFormat = TStyleFormat(LFormatString.ToInt());
}
catch(...)
{
LStyleFormat = static_cast<TStyleFormat>(-1); // Undefined
}
}
switch(LStyleFormat)
{
case TStyleFormat::Indexed:
LOutputFileName = ChangeFileExt(LInputFileName, ".idx");
break;
case TStyleFormat::Binary:
LOutputFileName = ChangeFileExt(LInputFileName, ".bin");
break;
case TStyleFormat::Text:
LOutputFileName = ChangeFileExt(LInputFileName, ".txt");
break;
default:
throw(Exception("Invalid format specified"));
}
TFmxObject* LStyle = NULL;
TMemoryStream* MemStream = NULL;
try
{
LStyle = Fmx::Styles::TStyleStreaming::LoadFromFile(LInputFileName);
//RemoveAuthorInfo(LStyle);
MemStream = new TMemoryStream();
Fmx::Styles::TStyleStreaming::SaveToStream(
LStyle, MemStream, LStyleFormat);
MemStream->SaveToFile(LOutputFileName);
}
__finally
{
delete LStyle;
delete MemStream;
}
}
/**
* This method will remove author information from the style.
* @param AObject A style object.
*/
void __fastcall TStyleConverterApplication::RemoveAuthorInfo(Fmx::Types::TFmxObject* AObject)
{
for(int i = 0; i < AObject->ChildrenCount; ++i)
{
TStyleDescription* LDescription = dynamic_cast<TStyleDescription*>(AObject->Children->Items[i]);
if(LDescription != NULL)
{
LDescription->Author = "";
LDescription->AuthorURL = "";
LDescription->AuthorEMail = "";
break;
}
}
}