-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleConverterApplication.cpp
More file actions
104 lines (95 loc) · 3.07 KB
/
StyleConverterApplication.cpp
File metadata and controls
104 lines (95 loc) · 3.07 KB
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
//---------------------------------------------------------------------------
#pragma hdrstop
#include "StyleConverterApplication.h"
#include <System.Classes.hpp>
#include <FMX.Styles.hpp>
#include <memory>
//---------------------------------------------------------------------------
#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;
}
/**
* Run.
*/
void __fastcall TStyleConverterApplication::Run()
{
if(ParamCount() < 1)
{
const String Usage = "Copyright (c) 2014-2024 Crayon Application" \
"\nUsage: StyleConverter.exe file [-f format]" \
"\nfile\tstyle file to convert" \
"\n -f\tformat: 0=Indexed, 1=Binary, 2=Text";
// "\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 = nullptr;
try
{
LStyle = Fmx::Styles::TStyleStreaming::LoadFromFile(LInputFileName);
//RemoveAuthorInfo(LStyle);
auto MemStream = std::make_unique<TMemoryStream>();
Fmx::Styles::TStyleStreaming::SaveToStream(
LStyle, MemStream.get(), LStyleFormat);
MemStream->SaveToFile(LOutputFileName);
}
__finally
{
delete LStyle;
}
}
/**
* 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)
{
auto LDescription = dynamic_cast<TStyleDescription*>(AObject->Children->Items[i]);
if(LDescription != nullptr)
{
LDescription->Author = "";
LDescription->AuthorURL = "";
LDescription->AuthorEMail = "";
break;
}
}
}