Commit 0c154269 authored by nanahira's avatar nanahira

backup

parent 97227afa
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "network.h" #include "network.h"
#include "game.h" #include "game.h"
#include "base64.h" #include "base64.h"
#include "lzma/LzmaLib.h"
#include <algorithm> #include <algorithm>
namespace ygo { namespace ygo {
...@@ -249,6 +250,14 @@ bool DeckManager::LoadDeck(const wchar_t* file) { ...@@ -249,6 +250,14 @@ bool DeckManager::LoadDeck(const wchar_t* file) {
} }
fclose(fp); fclose(fp);
LoadDeck(current_deck, cardlist, mainc, sidec); 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; return true;
} }
bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) { bool DeckManager::SaveDeck(Deck& deck, const wchar_t* name) {
...@@ -294,9 +303,7 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) { ...@@ -294,9 +303,7 @@ int DeckManager::TypeCount(std::vector<code_pointer> list, unsigned int ctype) {
return res; return res;
} }
bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) { bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) {
char data[1024]; char data[1024], *pdeck = data, *data_ = data;
char *pdeck = data;
char *data_ = data;
int decoded_len = Base64::DecodedLength(code, len); int decoded_len = Base64::DecodedLength(code, len);
if(decoded_len < 8 || !Base64::Decode(code, len, data_, decoded_len)) if(decoded_len < 8 || !Base64::Decode(code, len, data_, decoded_len))
return false; return false;
...@@ -306,8 +313,7 @@ bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) { ...@@ -306,8 +313,7 @@ bool DeckManager::LoadDeckFromCode(Deck& deck, const char *code, int len) {
return (errorcode == 0); return (errorcode == 0);
} }
int DeckManager::SaveDeckToCode(Deck& deck, char* code) { int DeckManager::SaveDeckToCode(Deck& deck, char* code) {
char deckbuf[1024]; char deckbuf[1024], *pdeck = deckbuf;
char* pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deck.main.size() + deck.extra.size()); BufferIO::WriteInt32(pdeck, deck.main.size() + deck.extra.size());
BufferIO::WriteInt32(pdeck, deck.side.size()); BufferIO::WriteInt32(pdeck, deck.side.size());
for(size_t i = 0; i < deck.main.size(); ++i) for(size_t i = 0; i < deck.main.size(); ++i)
...@@ -316,9 +322,17 @@ int DeckManager::SaveDeckToCode(Deck& deck, char* code) { ...@@ -316,9 +322,17 @@ int DeckManager::SaveDeckToCode(Deck& deck, char* code) {
BufferIO::WriteInt32(pdeck, deck.extra[i]->first); BufferIO::WriteInt32(pdeck, deck.extra[i]->first);
for(size_t i = 0; i < deck.side.size(); ++i) for(size_t i = 0; i < deck.side.size(); ++i)
BufferIO::WriteInt32(pdeck, deck.side[i]->first); BufferIO::WriteInt32(pdeck, deck.side[i]->first);
int len = pdeck - deckbuf; char cdata[1024], *pcdata = cdata, header[8], *pheader = header;
int encoded_len = Base64::EncodedLength(len); size_t propsize = 5, comp_size = 0x100;
Base64::Encode(deckbuf, len, code, encoded_len); 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; 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