Compare commits

..

3 Commits

Author SHA1 Message Date
zsyg
e47f905a8c Add files via upload 2025-07-07 16:59:18 +08:00
zsyg
6899e4767f 添加文本转换器程序 2025-07-07 16:53:44 +08:00
zsyg
d5a0564847 添加文本转换器代码 2025-07-07 16:52:56 +08:00
34 changed files with 681 additions and 3 deletions

View File

@@ -57,7 +57,7 @@ namespace AppStore
// 初始化并添加应用信息 // 初始化并添加应用信息
infoLabel = new Label(); infoLabel = new Label();
infoLabel.Text = "kortapp-z\n版本: 1.2.5\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和C/C++的软件"; infoLabel.Text = "kortapp-z\n版本: 1.2.6\n作者: zs-yg\n一个简单、开源的应用商店\nkortapp-z是完全免费\n基于.NET8和C/C++的软件";
infoLabel.Font = new Font("Microsoft YaHei", 12); infoLabel.Font = new Font("Microsoft YaHei", 12);
infoLabel.AutoSize = false; infoLabel.AutoSize = false;
infoLabel.Width = 300; infoLabel.Width = 300;

View File

@@ -569,6 +569,43 @@ namespace AppStore
} }
flowPanel.Controls.Add(iconExtractorCard); flowPanel.Controls.Add(iconExtractorCard);
// 文本转换器工具卡片
var textConverterCard = new ToolCard();
textConverterCard.ToolName = "文本转换器";
try
{
string iconPath = Path.Combine(Application.StartupPath, "img", "resource", "png", "text converter.png");
if (File.Exists(iconPath))
{
textConverterCard.ToolIcon = Image.FromFile(iconPath);
}
else
{
textConverterCard.ToolIcon = SystemIcons.Shield.ToBitmap();
}
}
catch
{
textConverterCard.ToolIcon = SystemIcons.Shield.ToBitmap();
}
textConverterCard.UpdateDisplay();
textConverterCard.ToolCardClicked += (s, e) => {
try {
string toolPath = Path.Combine(Application.StartupPath, "resource", "text_converter.exe");
if (File.Exists(toolPath)) {
Process.Start(toolPath);
} else {
MessageBox.Show("文本转换器工具未找到,请确保已正确安装", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} catch (Exception ex) {
MessageBox.Show($"启动文本转换器失败: {ex.Message}", "错误",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
};
flowPanel.Controls.Add(textConverterCard);
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -2,7 +2,7 @@
; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档! ; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档!
#define MyAppName "kortapp-z" #define MyAppName "kortapp-z"
#define MyAppVersion "1.2.5" #define MyAppVersion "1.2.6"
#define MyAppPublisher "zsyg" #define MyAppPublisher "zsyg"
#define MyAppURL "https://github.com/zs-yg/kortapp-z" #define MyAppURL "https://github.com/zs-yg/kortapp-z"
#define MyAppExeName "kortapp-z.exe" #define MyAppExeName "kortapp-z.exe"

View File

@@ -2,7 +2,7 @@
; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档! ; 有关创建 Inno Setup 脚本文件的详细信息,请参阅帮助文档!
#define MyAppName "kortapp-z" #define MyAppName "kortapp-z"
#define MyAppVersion "1.2.5" #define MyAppVersion "1.2.6"
#define MyAppPublisher "zsyg" #define MyAppPublisher "zsyg"
#define MyAppURL "https://github.com/zs-yg/kortapp-z" #define MyAppURL "https://github.com/zs-yg/kortapp-z"
#define MyAppExeName "kortapp-z.exe" #define MyAppExeName "kortapp-z.exe"

View File

@@ -0,0 +1,37 @@
# 编译器设置
CXX = g++
FLTK_CONFIG = fltk-config
# 编译选项
CXXFLAGS = -std=c++11 -Wall -Iinclude
LDFLAGS = -static -mwindows `$(FLTK_CONFIG) --use-images --ldstaticflags` -lcrypto -lws2_32 -lcrypt32
# 源文件和目标文件
SRC_DIR = src
OBJ_DIR = obj
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
OBJS = $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRCS))
# 可执行文件
TARGET = text_converter.exe
# 默认目标
all: $(OBJ_DIR) $(TARGET)
# 创建obj目录
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
# 生成目标文件
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# 链接生成可执行文件
$(TARGET): $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS)
# 清理
clean:
rm -rf $(OBJ_DIR) $(TARGET)
.PHONY: all clean

View File

@@ -0,0 +1,16 @@
#ifndef ABOUT_HPP
#define ABOUT_HPP
#include <string>
class About {
public:
static std::string getName() { return "文本转换器"; }
static std::string getVersion() { return "1.0.0"; }
static std::string getAuthor() { return "zsyg"; }
static std::string getDescription() {
return "一个简单的文本转换工具,支持文本转换";
}
};
#endif // ABOUT_HPP

View File

@@ -0,0 +1,13 @@
#ifndef ASCII85CONVERTER_HPP
#define ASCII85CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class Ascii85Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "Ascii85"; }
};
#endif // ASCII85CONVERTER_HPP

View File

@@ -0,0 +1,13 @@
#ifndef BASE32CONVERTER_HPP
#define BASE32CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class Base32Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "Base32"; }
};
#endif // BASE32CONVERTER_HPP

View File

@@ -0,0 +1,13 @@
#ifndef BASE64CONVERTER_HPP
#define BASE64CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class Base64Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "Base64"; }
};
#endif // BASE64CONVERTER_HPP

View File

@@ -0,0 +1,14 @@
#ifndef BINARYCONVERTER_HPP
#define BINARYCONVERTER_HPP
#include "Converter.hpp"
#include <string>
#include <bitset>
class BinaryConverter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "二进制"; }
};
#endif // BINARYCONVERTER_HPP

View File

@@ -0,0 +1,13 @@
#ifndef CRC32CONVERTER_HPP
#define CRC32CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class CRC32Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "CRC32"; }
};
#endif // CRC32CONVERTER_HPP

View File

@@ -0,0 +1,30 @@
#ifndef CONFIG_HPP
#define CONFIG_HPP
namespace Config {
constexpr int WINDOW_WIDTH = 450;
constexpr int WINDOW_HEIGHT = 250;
constexpr const char* WINDOW_TITLE = "文本转换器";
constexpr int INPUT_X = 70;
constexpr int INPUT_Y = 40;
constexpr int INPUT_WIDTH = 360;
constexpr int INPUT_HEIGHT = 30;
constexpr int OUTPUT_X = 70;
constexpr int OUTPUT_Y = 100;
constexpr int OUTPUT_WIDTH = 360;
constexpr int OUTPUT_HEIGHT = 30;
constexpr int CHOICE_X = 70;
constexpr int CHOICE_Y = 160;
constexpr int CHOICE_WIDTH = 120;
constexpr int CHOICE_HEIGHT = 30;
constexpr int BUTTON_X = 210;
constexpr int BUTTON_Y = 160;
constexpr int BUTTON_WIDTH = 100;
constexpr int BUTTON_HEIGHT = 30;
};
#endif // CONFIG_HPP

View File

@@ -0,0 +1,13 @@
#ifndef CONVERTER_HPP
#define CONVERTER_HPP
#include <string>
class Converter {
public:
virtual ~Converter() = default;
virtual std::string convert(const std::string& input) = 0;
virtual std::string getName() const = 0;
};
#endif // CONVERTER_HPP

View File

@@ -0,0 +1,15 @@
#ifndef HEXCONVERTER_HPP
#define HEXCONVERTER_HPP
#include "Converter.hpp"
#include <string>
#include <iomanip>
#include <sstream>
class HexConverter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "十六进制"; }
};
#endif // HEXCONVERTER_HPP

View File

@@ -0,0 +1,13 @@
#ifndef MD5CONVERTER_HPP
#define MD5CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class MD5Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "MD5"; }
};
#endif // MD5CONVERTER_HPP

View File

@@ -0,0 +1,26 @@
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Choice.H>
class MainWindow : public Fl_Window {
public:
MainWindow(int w, int h, const char* title);
~MainWindow();
private:
Fl_Input* inputText;
Fl_Output* outputText;
Fl_Choice* conversionType;
Fl_Button* convertButton;
static void ConvertCallback(Fl_Widget* widget, void* data);
void ConvertText();
};
#endif // MAINWINDOW_HPP

View File

@@ -0,0 +1,14 @@
#ifndef ROT13CONVERTER_HPP
#define ROT13CONVERTER_HPP
#include "Converter.hpp"
#include <string>
#include <cctype>
class ROT13Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "ROT13"; }
};
#endif // ROT13CONVERTER_HPP

View File

@@ -0,0 +1,13 @@
#ifndef SHA1CONVERTER_HPP
#define SHA1CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class SHA1Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "SHA1"; }
};
#endif // SHA1CONVERTER_HPP

View File

@@ -0,0 +1,13 @@
#ifndef SHA256CONVERTER_HPP
#define SHA256CONVERTER_HPP
#include "Converter.hpp"
#include <string>
class SHA256Converter : public Converter {
public:
std::string convert(const std::string& input) override;
std::string getName() const override { return "SHA256"; }
};
#endif // SHA256CONVERTER_HPP

View File

@@ -0,0 +1,14 @@
#ifndef UTILS_HPP
#define UTILS_HPP
#include <memory>
#include "Converter.hpp"
#include "BinaryConverter.hpp"
#include "HexConverter.hpp"
class Utils {
public:
static std::unique_ptr<Converter> createConverter(int type);
};
#endif // UTILS_HPP

View File

@@ -0,0 +1,47 @@
#include "../include/Ascii85Converter.hpp"
#include <string>
#include <cmath>
#include <sstream>
#include <cstdint>
const std::string ASCII85_PREFIX = "<~";
const std::string ASCII85_SUFFIX = "~>";
std::string Ascii85Converter::convert(const std::string& input) {
std::stringstream result;
result << ASCII85_PREFIX;
size_t i = 0;
while (i < input.size()) {
uint32_t value = 0;
int bytes = 0;
// 读取4个字节
for (int j = 0; j < 4 && (i + j) < input.size(); j++) {
value = (value << 8) | static_cast<unsigned char>(input[i + j]);
bytes++;
}
i += bytes;
// 特殊处理全0的4字节
if (value == 0 && bytes == 4) {
result << 'z';
continue;
}
// 转换为Ascii85
char chars[5];
for (int j = 4; j >= 0; j--) {
chars[j] = value % 85 + '!';
value /= 85;
}
// 写入结果(只写入bytes+1个字符)
for (int j = 0; j < bytes + 1; j++) {
result << chars[j];
}
}
result << ASCII85_SUFFIX;
return result.str();
}

View File

@@ -0,0 +1,37 @@
#include "../include/Base32Converter.hpp"
#include <string>
#include <stdexcept>
const std::string BASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
std::string Base32Converter::convert(const std::string& input) {
std::string result;
int buffer = 0;
int bitsLeft = 0;
int count = 0;
for (unsigned char c : input) {
buffer <<= 8;
buffer |= c;
bitsLeft += 8;
count++;
while (bitsLeft >= 5) {
int index = (buffer >> (bitsLeft - 5)) & 0x1F;
result += BASE32_CHARS[index];
bitsLeft -= 5;
}
}
if (bitsLeft > 0) {
int index = (buffer << (5 - bitsLeft)) & 0x1F;
result += BASE32_CHARS[index];
}
// 添加填充字符
while (result.size() % 8 != 0) {
result += '=';
}
return result;
}

View File

@@ -0,0 +1,22 @@
#include "../include/Base64Converter.hpp"
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <string>
std::string Base64Converter::convert(const std::string& input) {
// Base64编码
BIO *b64 = BIO_new(BIO_f_base64());
BIO *bio = BIO_new(BIO_s_mem());
BIO_push(b64, bio);
BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
BIO_write(b64, input.c_str(), input.length());
BIO_flush(b64);
char* buffer;
long length = BIO_get_mem_data(bio, &buffer);
std::string result(buffer, length);
BIO_free_all(b64);
return result;
}

View File

@@ -0,0 +1,27 @@
#include "../include/BinaryConverter.hpp"
#include <bitset>
#include <sstream>
#include <algorithm>
std::string BinaryConverter::convert(const std::string& input) {
if (input.empty()) {
return "";
}
std::stringstream result;
for (char c : input) {
std::string binary = std::bitset<8>(c).to_string();
// 去除前导0保留后6位
size_t firstOne = binary.find('1');
if (firstOne != std::string::npos) {
binary = binary.substr(firstOne);
}
result << binary << " ";
}
std::string output = result.str();
if (!output.empty()) {
output.pop_back(); // 移除最后一个空格
}
return output;
}

View File

@@ -0,0 +1,28 @@
#include "../include/CRC32Converter.hpp"
#include <string>
#include <sstream>
#include <iomanip>
#include <cstdint>
// CRC32多项式
const uint32_t CRC32_POLY = 0xEDB88320;
uint32_t computeCRC32(const std::string& input) {
uint32_t crc = 0xFFFFFFFF;
for (char c : input) {
crc ^= static_cast<unsigned char>(c);
for (int i = 0; i < 8; i++) {
crc = (crc >> 1) ^ ((crc & 1) ? CRC32_POLY : 0);
}
}
return ~crc;
}
std::string CRC32Converter::convert(const std::string& input) {
uint32_t crc = computeCRC32(input);
std::stringstream ss;
ss << std::hex << std::setw(8) << std::setfill('0') << crc;
return ss.str();
}

View File

@@ -0,0 +1,23 @@
#include "../include/HexConverter.hpp"
#include <iomanip>
#include <sstream>
std::string HexConverter::convert(const std::string& input) {
if (input.empty()) {
return "";
}
std::stringstream result;
for (char c : input) {
result << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<int>(static_cast<unsigned char>(c)) << " ";
}
std::string output = result.str();
// 移除最后一个空格
if (!output.empty()) {
output.pop_back();
}
return output;
}

View File

@@ -0,0 +1,23 @@
#include "../include/MD5Converter.hpp"
#include <openssl/evp.h>
#include <sstream>
#include <iomanip>
std::string MD5Converter::convert(const std::string& input) {
EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
const EVP_MD* md = EVP_md5();
unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int digest_len;
EVP_DigestInit_ex(mdctx, md, nullptr);
EVP_DigestUpdate(mdctx, input.c_str(), input.length());
EVP_DigestFinal_ex(mdctx, digest, &digest_len);
EVP_MD_CTX_free(mdctx);
std::stringstream ss;
for(unsigned int i = 0; i < digest_len; i++) {
ss << std::hex << std::setw(2) << std::setfill('0') << (int)digest[i];
}
return ss.str();
}

View File

@@ -0,0 +1,14 @@
#include "../include/MainWindow.hpp"
#include "../include/Config.hpp"
#include <FL/Fl.H>
int main(int argc, char **argv) {
// 创建主窗口
MainWindow window(Config::WINDOW_WIDTH, Config::WINDOW_HEIGHT, Config::WINDOW_TITLE);
// 显示窗口
window.show(argc, argv);
// 运行FLTK主循环
return Fl::run();
}

View File

@@ -0,0 +1,66 @@
#include "../include/MainWindow.hpp"
#include "../include/Utils.hpp"
#include "../include/Config.hpp"
#include <FL/Fl_Box.H>
#include <FL/fl_ask.H>
MainWindow::MainWindow(int w, int h, const char* title) : Fl_Window(w, h, title) {
// 初始化UI元素
inputText = new Fl_Input(Config::INPUT_X, Config::INPUT_Y,
Config::INPUT_WIDTH, Config::INPUT_HEIGHT, "输入文本:");
outputText = new Fl_Output(Config::OUTPUT_X, Config::OUTPUT_Y,
Config::OUTPUT_WIDTH, Config::OUTPUT_HEIGHT, "输出结果:");
conversionType = new Fl_Choice(Config::CHOICE_X, Config::CHOICE_Y,
Config::CHOICE_WIDTH, Config::CHOICE_HEIGHT, "转换类型:");
convertButton = new Fl_Button(Config::BUTTON_X, Config::BUTTON_Y,
Config::BUTTON_WIDTH, Config::BUTTON_HEIGHT, "转换");
// 设置转换类型选项
conversionType->add("二进制");
conversionType->add("十六进制");
conversionType->add("ROT13");
conversionType->add("MD5");
conversionType->add("SHA1");
conversionType->add("SHA256");
conversionType->add("Base64");
conversionType->add("Base32");
conversionType->add("Ascii85");
conversionType->add("CRC32");
conversionType->value(0); // 默认选择二进制
// 设置按钮回调
convertButton->callback(ConvertCallback, this);
end(); // 结束窗口组件添加
}
MainWindow::~MainWindow() {
// 清理资源
delete inputText;
delete outputText;
delete conversionType;
delete convertButton;
}
void MainWindow::ConvertCallback(Fl_Widget* widget, void* data) {
MainWindow* window = static_cast<MainWindow*>(data);
window->ConvertText();
}
void MainWindow::ConvertText() {
const char* input = inputText->value();
if (!input || strlen(input) == 0) {
fl_alert("请输入要转换的文本");
return;
}
int type = conversionType->value();
auto converter = Utils::createConverter(type);
if (!converter) {
fl_alert("不支持的转换类型");
return;
}
std::string result = converter->convert(input);
outputText->value(result.c_str());
}

View File

@@ -0,0 +1,13 @@
#include "../include/ROT13Converter.hpp"
std::string ROT13Converter::convert(const std::string& input) {
std::string result;
for (char c : input) {
if (isalpha(c)) {
char base = isupper(c) ? 'A' : 'a';
c = (c - base + 13) % 26 + base;
}
result += c;
}
return result;
}

View File

@@ -0,0 +1,23 @@
#include "../include/SHA1Converter.hpp"
#include <openssl/evp.h>
#include <sstream>
#include <iomanip>
std::string SHA1Converter::convert(const std::string& input) {
EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
const EVP_MD* md = EVP_sha1();
unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int digest_len;
EVP_DigestInit_ex(mdctx, md, nullptr);
EVP_DigestUpdate(mdctx, input.c_str(), input.length());
EVP_DigestFinal_ex(mdctx, digest, &digest_len);
EVP_MD_CTX_free(mdctx);
std::stringstream ss;
for(unsigned int i = 0; i < digest_len; i++) {
ss << std::hex << std::setw(2) << std::setfill('0') << (int)digest[i];
}
return ss.str();
}

View File

@@ -0,0 +1,23 @@
#include "../include/SHA256Converter.hpp"
#include <openssl/evp.h>
#include <sstream>
#include <iomanip>
std::string SHA256Converter::convert(const std::string& input) {
EVP_MD_CTX* mdctx = EVP_MD_CTX_new();
const EVP_MD* md = EVP_sha256();
unsigned char digest[EVP_MAX_MD_SIZE];
unsigned int digest_len;
EVP_DigestInit_ex(mdctx, md, nullptr);
EVP_DigestUpdate(mdctx, input.c_str(), input.length());
EVP_DigestFinal_ex(mdctx, digest, &digest_len);
EVP_MD_CTX_free(mdctx);
std::stringstream ss;
for(unsigned int i = 0; i < digest_len; i++) {
ss << std::hex << std::setw(2) << std::setfill('0') << (int)digest[i];
}
return ss.str();
}

View File

@@ -0,0 +1,25 @@
#include "../include/Utils.hpp"
#include "../include/ROT13Converter.hpp"
#include "../include/MD5Converter.hpp"
#include "../include/SHA1Converter.hpp"
#include "../include/SHA256Converter.hpp"
#include "../include/Base64Converter.hpp"
#include "../include/Base32Converter.hpp"
#include "../include/Ascii85Converter.hpp"
#include "../include/CRC32Converter.hpp"
std::unique_ptr<Converter> Utils::createConverter(int type) {
switch (type) {
case 0: return std::unique_ptr<Converter>(new BinaryConverter());
case 1: return std::unique_ptr<Converter>(new HexConverter());
case 2: return std::unique_ptr<Converter>(new ROT13Converter());
case 3: return std::unique_ptr<Converter>(new MD5Converter());
case 4: return std::unique_ptr<Converter>(new SHA1Converter());
case 5: return std::unique_ptr<Converter>(new SHA256Converter());
case 6: return std::unique_ptr<Converter>(new Base64Converter());
case 7: return std::unique_ptr<Converter>(new Base32Converter());
case 8: return std::unique_ptr<Converter>(new Ascii85Converter());
case 9: return std::unique_ptr<Converter>(new CRC32Converter());
default: return nullptr;
}
}

BIN
resource/text_converter.exe Normal file

Binary file not shown.