Skip to content

Commit 1cbbfd3

Browse files
committed
Refactor: Adjust code structure
1 parent e48f427 commit 1cbbfd3

File tree

8 files changed

+55
-42
lines changed

8 files changed

+55
-42
lines changed

exporter/src/aecommand/AECommand.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "AECommand.h"
2020
#include "utils/AEHelper.h"
21-
#include "utils/AEResourceManager.h"
21+
#include "utils/AEResource.h"
2222

2323
namespace exporter {
2424

@@ -30,7 +30,8 @@ AEGP_Command AECommand::PAGPreviewCMD = 0L;
3030
A_Err AECommand::OnUpdateMenu(AEGP_GlobalRefcon /*globalRefcon*/,
3131
AEGP_UpdateMenuRefcon /*menuRefcon*/,
3232
AEGP_WindowType /*windowType*/) {
33-
A_Err err = A_Err_NONE, err2 = A_Err_NONE;
33+
A_Err err = A_Err_NONE;
34+
A_Err err2 = A_Err_NONE;
3435
const auto& suites = AEHelper::GetSuites();
3536
AEGP_ItemH active_itemH = AEHelper::GetActiveCompositionItem();
3637
if (active_itemH) {
@@ -42,7 +43,7 @@ A_Err AECommand::OnUpdateMenu(AEGP_GlobalRefcon /*globalRefcon*/,
4243
}
4344

4445
ERR(suites->CommandSuite1()->AEGP_EnableCommand(PAGConfigCMD));
45-
if (AEResourceManager::HasCompositionResource()) {
46+
if (exporter::HasCompositionResource()) {
4647
ERR(suites->CommandSuite1()->AEGP_EnableCommand(PAGPanelCMD));
4748
} else {
4849
ERR2(suites->CommandSuite1()->AEGP_DisableCommand(PAGPanelCMD));

exporter/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
extern "C" DllExport A_Err EntryPointFunc(struct SPBasicSuite* suite, A_long /*majorVersion*/,
2727
A_long /*minorVersion*/, AEGP_PluginID pluginID,
2828
AEGP_GlobalRefcon* /*globalRefcon*/) {
29-
exporter::AEHelper::SetSuitesAndPluginID(suite, pluginID);
29+
AEHelper::SetSuitesAndPluginID(suite, pluginID);
3030
A_Err err = A_Err_NONE;
3131
A_Err err2 = A_Err_NONE;
32-
const auto& suites = exporter::AEHelper::GetSuites();
32+
const auto& suites = AEHelper::GetSuites();
3333

3434
// PAG Config...
3535
ERR(suites->CommandSuite1()->AEGP_GetUniqueCommand(&exporter::AECommand::PAGConfigCMD));

exporter/src/platform/mac/PlatformHelper.mm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/////////////////////////////////////////////////////////////////////////////////////////////////
1818
#include "platform/PlatformHelper.h"
1919
#import <Foundation/Foundation.h>
20+
namespace exporter {
2021
std::string GetRoamingPath() {
2122
NSArray* arr =
2223
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
@@ -31,10 +32,15 @@
3132
NSFileManager* fileManager = [NSFileManager defaultManager];
3233
NSString* nsPath = [NSString stringWithUTF8String:path.c_str()];
3334
if (![fileManager fileExistsAtPath:nsPath]) {
34-
[fileManager createDirectoryAtPath:nsPath
35-
withIntermediateDirectories:YES
36-
attributes:nil
37-
error:nil];
35+
NSError* error = nil;
36+
if (![fileManager createDirectoryAtPath:nsPath
37+
withIntermediateDirectories:YES
38+
attributes:nil
39+
error:&error]) {
40+
NSLog(@"Failed to create directory: %@", error);
41+
return "";
42+
}
3843
}
3944
return path;
40-
}
45+
}
46+
} // namespace exporter

exporter/src/platform/win/PlatformHelper.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ std::string GetRoamingPath() {
3737
return path + "\\";
3838
}
3939

40-
void CreateFolder(const std::string& path) {
40+
bool CreateFolder(const std::string& path) {
4141
if (!fs::exists(path)) {
42-
fs::create_directories(path);
42+
std::error_code errorCode;
43+
if (!fs::create_directories(path, errorCode)) {
44+
printf("Create %s failed: %s\n", path.c_str(), errorCode.message().c_str());
45+
return false;
46+
}
4347
}
48+
return true;
4449
}
4550

4651
std::string GetConfigPath() {
@@ -50,7 +55,9 @@ std::string GetConfigPath() {
5055
}
5156

5257
path += "PAGExporter\\";
53-
CreateFolder(path);
58+
if (!CreateFolder(path)) {
59+
return "";
60+
}
5461
return path;
5562
}
5663

exporter/src/utils/AEHelper.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
#include "AEHelper.h"
2020

21-
namespace exporter {
21+
namespace AEHelper {
2222

23-
AEGP_PluginID AEHelper::PluginID = 0L;
24-
std::shared_ptr<AEGP_SuiteHandler> AEHelper::Suites = nullptr;
23+
AEGP_PluginID PluginID = 0L;
24+
std::shared_ptr<AEGP_SuiteHandler> Suites = nullptr;
2525

26-
void AEHelper::SetSuitesAndPluginID(SPBasicSuite* basicSuite, AEGP_PluginID id) {
27-
Suites = std::make_unique<AEGP_SuiteHandler>(basicSuite);
26+
void SetSuitesAndPluginID(SPBasicSuite* basicSuite, AEGP_PluginID id) {
27+
Suites = std::make_shared<AEGP_SuiteHandler>(basicSuite);
2828
PluginID = id;
2929
}
3030

31-
AEGP_ItemH AEHelper::GetActiveCompositionItem() {
31+
AEGP_ItemH GetActiveCompositionItem() {
3232
const auto& suites = GetSuites();
3333
AEGP_ItemH activeItemH = nullptr;
3434
suites->ItemSuite6()->AEGP_GetActiveItem(&activeItemH);
@@ -48,4 +48,12 @@ AEGP_ItemH AEHelper::GetActiveCompositionItem() {
4848
return activeItemH;
4949
}
5050

51-
} // namespace exporter
51+
AEGP_PluginID GetPluginID() {
52+
return PluginID;
53+
}
54+
55+
std::shared_ptr<AEGP_SuiteHandler> GetSuites() {
56+
return Suites;
57+
}
58+
59+
} // namespace AEHelper

exporter/src/utils/AEHelper.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,14 @@
2222
#include "AEGP_SuiteHandler.h"
2323
#include "AE_GeneralPlug.h"
2424

25-
namespace exporter {
25+
namespace AEHelper {
2626

27-
class AEHelper {
28-
public:
29-
static AEGP_ItemH GetActiveCompositionItem();
30-
static void SetSuitesAndPluginID(SPBasicSuite* basicSuite, AEGP_PluginID id);
31-
static std::shared_ptr<AEGP_SuiteHandler> GetSuites() {
32-
return Suites;
33-
}
34-
static AEGP_PluginID GetPluginID() {
35-
return PluginID;
36-
}
27+
AEGP_ItemH GetActiveCompositionItem();
3728

38-
private:
39-
static AEGP_PluginID PluginID;
40-
static std::shared_ptr<AEGP_SuiteHandler> Suites;
41-
};
42-
} // namespace exporter
29+
void SetSuitesAndPluginID(SPBasicSuite* basicSuite, AEGP_PluginID id);
30+
31+
std::shared_ptr<AEGP_SuiteHandler> GetSuites();
32+
33+
AEGP_PluginID GetPluginID();
34+
35+
} // namespace AEHelper

exporter/src/utils/AEResourceManager.cpp renamed to exporter/src/utils/AEResource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//
1717
/////////////////////////////////////////////////////////////////////////////////////////////////
1818

19-
#include "AEResourceManager.h"
19+
#include "AEResource.h"
2020
#include "AEHelper.h"
2121

2222
namespace exporter {
@@ -48,7 +48,7 @@ static AEResourceType GetResourceType(const std::shared_ptr<AEGP_SuiteHandler>&
4848
return AEResourceType::Unknown;
4949
}
5050

51-
bool AEResourceManager::HasCompositionResource() {
51+
bool HasCompositionResource() {
5252
const auto& suites = AEHelper::GetSuites();
5353
A_long numProjects = 0;
5454
suites->ProjSuite6()->AEGP_GetNumProjects(&numProjects);

exporter/src/utils/AEResourceManager.h renamed to exporter/src/utils/AEResource.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace exporter {
2222

2323
enum class AEResourceType { Unknown, Folder, Composition, Image };
2424

25-
class AEResourceManager {
26-
public:
27-
static bool HasCompositionResource();
28-
};
25+
bool HasCompositionResource();
26+
2927
} // namespace exporter

0 commit comments

Comments
 (0)