74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
#include <wx/wx.h>
|
|
#include "git_repository.h"
|
|
#include "config_manager.h"
|
|
#include "main_frame.h"
|
|
|
|
class GitBranchApp : public wxApp {
|
|
public:
|
|
bool OnInit() override {
|
|
// 初始化Git库
|
|
if (!git::InitLibGit()) {
|
|
wxMessageBox("Failed to initialize libgit2", "Error", wxICON_ERROR);
|
|
return false;
|
|
}
|
|
|
|
// 加载配置
|
|
auto& config = ConfigManager::Instance();
|
|
if (!config.Load()) {
|
|
// 配置不存在或无效,初始化新配置
|
|
if (!InitializeConfig()) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// 打开主仓库
|
|
std::string repo_path = config.GetRepositoryPath();
|
|
auto repo = git::OpenRepository(repo_path);
|
|
if (!repo) {
|
|
wxMessageBox("Failed to open repository: " + repo_path, "Error", wxICON_ERROR);
|
|
return false;
|
|
}
|
|
|
|
// 创建并显示主窗口
|
|
auto* frame = new MainFrame("Git Branch Manager");
|
|
frame->Show(true);
|
|
|
|
return true;
|
|
}
|
|
|
|
int OnExit() override {
|
|
// 保存配置
|
|
ConfigManager::Instance().Save();
|
|
|
|
// 清理Git库
|
|
git::CleanupLibGit();
|
|
|
|
return 0;
|
|
}
|
|
|
|
private:
|
|
bool InitializeConfig() {
|
|
// 显示目录选择对话框
|
|
wxDirDialog dialog(nullptr, "Select Git Repository", "",
|
|
wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
|
|
|
|
if (dialog.ShowModal() != wxID_OK) {
|
|
return false;
|
|
}
|
|
|
|
std::string path = dialog.GetPath().ToStdString();
|
|
if (!git::IsValidRepository(path)) {
|
|
wxMessageBox("Please select a valid Git repository", "Error", wxICON_ERROR);
|
|
return false;
|
|
}
|
|
|
|
auto& config = ConfigManager::Instance();
|
|
config.SetRepositoryPath(path);
|
|
config.Save();
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
wxIMPLEMENT_APP(GitBranchApp);
|