Commit 0c154269 authored by nanahira's avatar nanahira

backup

parent 97227afa
......@@ -3,6 +3,7 @@
#include "network.h"
#include "game.h"
#include "base64.h"
#include "lzma/LzmaLib.h"
#include <algorithm>
namespace ygo {
......@@ -249,6 +250,14 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
}
fclose(fp);
LoadDeck(current_deck, cardlist, mainc, sidec);
{
char data[1024];
int len = SaveDeckToCode(current_deck, data);
if(len)
printf("[Base64]%ls: %d %s\n", localfile, len, data);
else
printf("[Base64]%ls: %d %s\n", localfile, len, "Failed");
}
return true;
}
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
......@@ -294,9 +303,7 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) {
return res;
}
bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) {
char data[1024];
char *pdeck = data;
char *data_ = data;
char data[1024], *pdeck = data, *data_ = data;
int decoded_len = Base64::DecodedLength(code, len);
if(decoded_len < 8 || !Base64::Decode(code, len, data_, decoded_len))
return false;
......@@ -306,8 +313,7 @@ bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) {
return (errorcode == 0);
}
int DeckManager::SaveDeckToCode(Deck& deck, char* code) {
char deckbuf[1024];
char* pdeck = deckbuf;
char deckbuf[1024], *pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deck.main.size() + deck.extra.size());
BufferIO::WriteInt32(pdeck, deck.side.size());
for(size_t i = 0; i < deck.main.size(); ++i)
......@@ -316,9 +322,17 @@ int DeckManager::SaveDeckToCode(Deck& deck, char* code) {
BufferIO::WriteInt32(pdeck, deck.extra[i]->first);
for(size_t i = 0; i < deck.side.size(); ++i)
BufferIO::WriteInt32(pdeck, deck.side[i]->first);
int len = pdeck - deckbuf;
int encoded_len = Base64::EncodedLength(len);
Base64::Encode(deckbuf, len, code, encoded_len);
char cdata[1024], *pcdata = cdata, header[8], *pheader = header;
size_t propsize = 5, comp_size = 0x100;
LzmaCompress(reinterpret_cast<unsigned char*>(pcdata), &comp_size, reinterpret_cast<unsigned char*>(deckbuf), pdeck - deckbuf, reinterpret_cast<unsigned char*>(pheader), &propsize, 9, 1 << 27, 3, 0, 2, 273, 1);
char fdata[1032], *pfdata = fdata;
memcpy(pfdata, header, 8);
const int fsize = comp_size + 8;
pfdata += 8;
memcpy(pfdata, pcdata, comp_size);
int encoded_len = Base64::EncodedLength(fsize);
if(!Base64::Encode(fdata, fsize, code, encoded_len))
return 0;
return encoded_len;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment