MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / LoadLightSettings

Function LoadLightSettings

BakingLab/BakingLab.cpp:106–164  ·  view source on GitHub ↗

Save lighting settings to a file

Source from the content-addressed store, hash-verified

104
105// Save lighting settings to a file
106static void LoadLightSettings(HWND parentWindow)
107{
108 wchar currDirectory[MAX_PATH] = { 0 };
109 GetCurrentDirectory(ArraySize_(currDirectory), currDirectory);
110
111 wchar filePath[MAX_PATH] = { 0 };
112
113 OPENFILENAME ofn;
114 ZeroMemory(&ofn , sizeof(ofn));
115 ofn.lStructSize = sizeof(ofn);
116 ofn.hwndOwner = parentWindow;
117 ofn.lpstrFile = filePath;
118 ofn.nMaxFile = ArraySize_(filePath);
119 ofn.lpstrFilter = L"All Files (*.*)\0*.*\0Light Settings (*.lts)\0*.lts\0";
120 ofn.nFilterIndex = 2;
121 ofn.lpstrFileTitle = nullptr;
122 ofn.nMaxFileTitle = 0;
123 ofn.lpstrInitialDir = nullptr;
124 ofn.lpstrTitle = L"Open Light Settings File..";
125 ofn.lpstrDefExt = L"lts";
126 ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
127 bool succeeded = GetOpenFileName(&ofn) != 0;
128 SetCurrentDirectory(currDirectory);
129
130 if(succeeded)
131 {
132 try
133 {
134 FileReadSerializer serializer(filePath);
135
136 std::vector<SettingInfo> settingInfo;
137 SerializeItem(serializer, settingInfo);
138
139 uint8 dummyBuffer[1024] = { 0 };
140 for(uint64 i = 0; i < settingInfo.size(); ++i)
141 {
142 const SettingInfo& info = settingInfo[i];
143 Setting* setting = Settings.FindSetting(info.Name);
144 if(setting == nullptr || setting->SerializedValueSize() != info.DataSize)
145 {
146 // Skip the data for this setting, it's out-of-date
147 Assert_(info.DataSize <= sizeof(dummyBuffer));
148 if(info.DataSize > 0)
149 serializer.SerializeData(info.DataSize, dummyBuffer);
150 continue;
151 }
152
153 setting->SerializeValue(serializer);
154 }
155 }
156 catch(Exception e)
157 {
158 std::wstring errorString = L"Error occured while loading light settings file: " + e.GetMessage();
159 MessageBox(parentWindow, errorString.c_str(), L"Error", MB_OK | MB_ICONERROR);
160 }
161 }
162
163 SetCurrentDirectory(currDirectory);

Callers 1

UpdateMethod · 0.85

Calls 6

SerializeItemFunction · 0.85
FindSettingMethod · 0.80
SerializedValueSizeMethod · 0.80
sizeMethod · 0.45
SerializeDataMethod · 0.45
SerializeValueMethod · 0.45

Tested by

no test coverage detected