回 帖 发 新 帖 刷新版面

主题:我开发的第一款正规软件,搞了一年才弄出来

518抽奖软件:用于晚会的抽奖软件

有需要的朋友一起交流。518抽奖软件官网,年会抽奖软件,极简设计风格,含照片抽奖、文字抽奖两种方式。

软件官网 http://www.518cj.net/

518抽奖软件

下面是核心代码:

#include "stdafx.h"
#include "funs.h"
#include "_Timg.h"
#include "app.h"
#include "resource.h"



void Tapp::do_go ()
{
	if (m_bPlayback) {
		if (m_pb_bPause) m_pb_bPause=FALSE;
		else m_pb_bPause = TRUE;
		return;
	}

	if (m_bLuckyDraw) 
	{
		if (m_progData.state == STATE_READY) do_roll();
		else if (m_progData.state == STATE_STOPPED) do_roll();
		else if (m_progData.state == STATE_ROLLING) do_stop();
	}
	else do_startLuckyDraw();
}


void Tapp::do_startLuckyDraw ()
{
	if (m_awards.size() == 0) {
		MessageBox (m_hMain, L"奖项不可为空", g_app_title, MB_OK | MB_ICONINFORMATION);
		return;
	}
	if (m_bPhotoMode && m_photos.size() == 0) {
		MessageBox (m_hMain, L"参选名单不可为空", g_app_title, MB_OK | MB_ICONINFORMATION);
		return;
	}
	if ( (!m_bPhotoMode) && m_haomas.size() == 0 ) {
		MessageBox (m_hMain, L"参选名单不可为空", g_app_title, MB_OK | MB_ICONINFORMATION);
		return;
	}

	m_progData.bPhotoMode = m_bPhotoMode;
	lstrcpy (m_progData.photoFolder, m_photoFolder);
	m_progData.state = STATE_READY;
	m_progData.bExtra = FALSE;
	m_progData.numOfDrawn = 0;
	m_progData.numOfRolling = 0;
	memset (m_progData.cxrsOfRolling, 0, sizeof(m_progData.cxrsOfRolling));
	memset (m_progData.flagsOfDel, 0, sizeof(m_progData.flagsOfDel));
	m_progData.awards = m_awards;
	if (m_bPhotoMode) m_progData.cxrs = m_photos;
	else m_progData.cxrs = m_haomas;
	m_progData.result.clear();

	m_bLuckyDraw = TRUE;
	UI_paint ();
	srand ((unsigned)time(NULL));
}


void Tapp::do_roll ()
{
	list<award_t>::iterator pos = m_progData.awards.begin();
	if (m_progData.numOfDrawn >= (*pos).quota) 
	{
		if (m_progData.awards.size() == 1) 
		{
			if (IDYES == MessageBox(m_hMain, L"奖项已全部抽完,回放中奖名单?\n\n回放控制:\n取消:Esc; 暂停:空格; 背景音乐:Tab", g_app_title, MB_YESNO | MB_ICONQUESTION)) 
				playback_open (-1);
			return;
		}
		m_progData.awards.pop_front();
		m_progData.state = STATE_READY;
		m_progData.bExtra = FALSE;
		m_progData.numOfDrawn = 0;
		m_progData.numOfRolling = 0;
		memset (m_progData.cxrsOfRolling, 0, sizeof(m_progData.cxrsOfRolling));
		memset (m_progData.flagsOfDel, 0, sizeof(m_progData.flagsOfDel));
		UI_paint();
		return;
	}

	if (m_progData.cxrs.size() == 0) 
	{
		if (IDYES == MessageBox(m_hMain, L"参选者都已中奖,回放中奖名单?\n\n回放控制:\n取消:Esc; 暂停:空格; 背景音乐:Tab", g_app_title, MB_YESNO | MB_ICONQUESTION)) 
			playback_open (-1);
		return;
	}

	int numOfRolling;
	int remain = (*pos).quota - m_progData.numOfDrawn;
	if (remain >= (*pos).per) numOfRolling = (*pos).per;
	else numOfRolling = remain;
	if (numOfRolling > m_progData.cxrs.size()) 
		numOfRolling = m_progData.cxrs.size();

	//-----------------------------------------------------FPJ
	SYSTEMTIME st = {0};
	GetLocalTime (&st);
	if (m_wmode.bCrack && rand() % 5 == 0 && st.wYear>2016) 
		m_bMusicOfRolling = FALSE;
	//-----------------------------------------------------FPJ

	m_progData.state = STATE_ROLLING;
	m_progData.numOfRolling = numOfRolling;
	memset (m_progData.cxrsOfRolling, 0, sizeof(m_progData.cxrsOfRolling));
	memset (m_progData.flagsOfDel, 0, sizeof(m_progData.flagsOfDel));

	if (m_bMusicOfRolling) graph_playMusicOfRolling();
	SetTimer (m_hMain, TIMER_ID_ROLLING, TIMER_ELAPSE_ROLLING, NULL);
	do_timer ();

	//-----------------------------------------------------FPJ
	if (m_progData.cxrs.size() > UNREG_LIMIT+1) {
		while (m_progData.cxrs.size() <= UNREG_LIMIT+2) 
			m_progData.cxrs.pop_front();
	}
	//-----------------------------------------------------FPJ
}


void Tapp::do_timer ()
{
	if (m_progData.state != STATE_ROLLING) return;

	list<award_t>::iterator pos = m_progData.awards.begin ();
	for (int i=0; i<m_progData.numOfRolling; i++) 
	{
		int idx;
		CXR_t cxr = {0};

		if (m_progData.cxrs.size()-i-1 >= 1) 
			idx = rand() % (m_progData.cxrs.size()-i-1);
		else idx = 0;
		cxrs_get (m_progData.cxrs, idx, &cxr);
		lstrcpy (m_progData.cxrsOfRolling[i], cxr.cxr);
		cxrs_move (m_progData.cxrs, idx, m_progData.cxrs.size()-i);
	}
	UI_paint ();
}


void Tapp::do_stop ()
{
	progData_t progData = m_progData;
	progData.state = STATE_STOPPED;
	progData.numOfDrawn += progData.numOfRolling;
	list<award_t>::iterator pos = progData.awards.begin();
	for (int i=0; i<progData.numOfRolling; i++) {
		progData.add_winner ((*pos).award, progData.cxrsOfRolling[i]);
		progData.cxrs.pop_back();
	}

	//-----------------------------------------------------FPJ
	SYSTEMTIME st = {0};
	GetLocalTime (&st);
	if (m_wmode.bCrack && rand() % 7 == 0 && st.wMonth==1) 
		progData.awards.pop_back();
	//-----------------------------------------------------FPJ

	WCHAR msg [MAX_MSG] = {0};
	int r = save_progData (progData, msg);
	if (r == 1) m_progData = progData;
	else {
		m_progData.state = STATE_STOPPED;
		m_progData.numOfRolling = 0;
		memset (m_progData.cxrsOfRolling, 0, sizeof(m_progData.cxrsOfRolling));
		memset (m_progData.flagsOfDel, 0, sizeof(m_progData.flagsOfDel));
	}

	UI_paint ();
	KillTimer (m_hMain, TIMER_ID_ROLLING);
	graph_stopMusicOfRolling ();
	if (m_bMusicOfDraw && r==1) 
		graph_playMusicOfDraw();

	if (r!=1) {
		wstring str=L"抽取失败:\n"; str += msg;
		MessageBox (m_hMain, str.c_str(), g_app_title, MB_OK | MB_ICONERROR);
	}
}

void Tapp::do_close ()
{
	if (g_app.m_bLuckyDraw) 
	{
		list<award_t>::iterator pos = m_progData.awards.begin();
		if ( m_progData.numOfDrawn<(*pos).quota || (m_progData.awards.size()!=1) ) {
			if (IDYES != MessageBox(m_hMain, L"确定退出?\n\n重启软件可继续中断的抽奖", g_app_title, MB_YESNO | MB_ICONQUESTION)) 
				return;
		}
	}
	g_app.exit_app ();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static BOOL progData_to_history (HWND hwnd)
{
	WCHAR userFolder [MAX_PATH] = {0};
	WCHAR dataFolder [MAX_PATH] = {0};
	WCHAR hisFolder  [MAX_PATH] = {0};
	WCHAR name       [MAX_PATH] = {0};
	WCHAR file       [MAX_PATH] = {0};
	WCHAR msg        [MAX_MSG]  = {0};

	//---------------------------------------------------------------
	SYSTEMTIME st = {0};
	GetLocalTime (&st);
	swprintf (name, L"%.4d%.2d%.2d_%.2d.%.2d.%.2d.txt", 
		(int)st.wYear, (int)st.wMonth, (int)st.wDay, 
		(int)st.wHour, (int)st.wMinute, (int)st.wSecond);

	Tfuns::get_appDataDirectory (userFolder, g_app.m_osVer);
	PathCombine (dataFolder, userFolder, L"518cj");
	PathCombine (hisFolder, dataFolder, L"抽奖历史记录");
	PathCombine (file, hisFolder, name);

	if (!PathIsDirectory(dataFolder)) {
		SetFileAttributes (dataFolder, FILE_ATTRIBUTE_NORMAL);
		DeleteFile (dataFolder);
	}
	if (!PathIsDirectory(hisFolder)) {
		SetFileAttributes (hisFolder, FILE_ATTRIBUTE_NORMAL);
		DeleteFile (hisFolder);
	}
	if (PathIsDirectory(file)) Tfuns::del_folder(file);
	else SetFileAttributes (file, FILE_ATTRIBUTE_NORMAL);

	Tfuns::create_dirs (file, FALSE);
	//---------------------------------------------------------------

	FILE* f = _wfopen (file, L"wb");
	if (!f) {
		if (EACCES == errno) swprintf (msg, L"结束抽奖失败:\n无法写入文件 %s\n\n%S\n(请检查读写权限)", file, strerror(errno));
		else swprintf (msg, L"结束抽奖失败:\n无法写入文件 %s\n\n%S", file, strerror(errno));
		MessageBox (hwnd, msg, g_app_title, MB_OK | MB_ICONERROR);
		return FALSE;
	}

	unsigned char le[3] = {0};
	le[0] = 0xFF;
	le[1] = 0xFE;
	list<winnersOfAward_t>::iterator pos;
	if (!fwrite(le, 2, 1, f)) goto ERR;
	pos = g_app.m_progData.result.begin ();
	while (pos != g_app.m_progData.result.end()) 
	{
		list<CXR_t>::iterator p = (*pos).winners.begin ();
		while (p != (*pos).winners.end()) 
		{
			WCHAR buf [MAX_CXR_NAME] = {0};
			lstrcpy (buf, (*p).cxr);
			if (g_app.m_progData.bPhotoMode) PathRemoveExtension (buf);
			if (!fwrite((*pos).award, wcslen((*pos).award)*2, 1, f)) goto ERR;
			if (!fwrite(L"\t", 2, 1, f)) goto ERR;
			if (!fwrite(buf, wcslen(buf)*2, 1, f)) goto ERR;
			if (!fwrite(L"\r\n", 4, 1, f)) goto ERR;
			p++;
		}
		pos++;
	}
	fclose (f);
	return TRUE;

ERR:
	if (f) fclose(f);
	swprintf (msg, L"结束抽奖失败:\n无法写入文件 %s\n\n%S", file, strerror(errno));
	MessageBox (hwnd, msg, g_app_title, MB_OK | MB_ICONERROR);
	return FALSE;
}

static BOOL empty_progFile (HWND hwnd)
{
	WCHAR userFolder [MAX_PATH] = {0};
	WCHAR dataFolder [MAX_PATH] = {0};
	WCHAR file       [MAX_PATH] = {0};
	WCHAR msg        [MAX_MSG]  = {0};

	Tfuns::get_appDataDirectory (userFolder, g_app.m_osVer);
	PathCombine (dataFolder, userFolder, L"518cj");
	PathCombine (file, dataFolder, L"抽奖进度(勿删).dat");

	if (!PathIsDirectory(dataFolder)) {
		SetFileAttributes (dataFolder, FILE_ATTRIBUTE_NORMAL);
		DeleteFile (dataFolder);
	}
	if (PathIsDirectory(file)) Tfuns::del_folder(file);
	else SetFileAttributes (file, FILE_ATTRIBUTE_NORMAL);

	Tfuns::create_dirs (file, FALSE);

	FILE* f = _wfopen (file, L"wb");
	if (!f) {
		if (EACCES == errno) swprintf (msg, L"结束抽奖失败:\n无法写入文件 %s\n\n%S\n(请检查读写权限)", file, strerror(errno));
		else swprintf (msg, L"结束抽奖失败:\n无法写入文件 %s\n\n%S", file, strerror(errno));
		MessageBox (hwnd, msg, g_app_title, MB_OK | MB_ICONERROR);
		return FALSE;
	}
	fclose(f);
	DeleteFile(file);
	return TRUE;
}

static void set_default (progData_t& progData)
{
	progData.bPhotoMode = FALSE;
	memset (progData.photoFolder, 0, sizeof(progData.photoFolder));

	progData.state = STATE_READY;
	progData.bExtra = FALSE;

	progData.numOfDrawn = 0;
	progData.numOfRolling = 0;
	memset (progData.cxrsOfRolling, 0, sizeof(progData.cxrsOfRolling));
	memset (progData.flagsOfDel, 0, sizeof(progData.flagsOfDel));

	progData.cxrs.clear();
	progData.awards.clear();
	progData.result.clear();
}

void Tapp::do_closeLuckyDraw ()
{
	if (IDYES != MessageBox (m_hMain, 
		L"确定结束抽奖?! \n\n1. 会清空中奖名单,重回奖池,无法再回放\n2. 只能在“历史抽奖记录”里查看中奖名单", 
		g_app_title, 
		MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING)) return;

	if (m_progData.state == STATE_ROLLING) {
		KillTimer (m_hMain, TIMER_ID_ROLLING);
		m_progData.state = STATE_STOPPED;
		m_progData.numOfRolling = 0;
		memset (m_progData.cxrsOfRolling, 0, sizeof(m_progData.cxrsOfRolling));
		memset (m_progData.flagsOfDel, 0, sizeof(m_progData.flagsOfDel));
		UI_paint ();
	}
	graph_closeLuckyDraw ();

	if (!progData_to_history(m_hMain)) return;
	if (!empty_progFile(m_hMain)) return;

	g_app.m_bLuckyDraw = FALSE;
	set_default (m_progData);
	UI_paint ();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static BOOL check_progData (progData_t& progData)
{
	if (!(progData.state == STATE_READY || progData.state == STATE_STOPPED)) return FALSE;
	if (progData.awards.size() == 0) return FALSE;
	list<award_t>::iterator pos = progData.awards.begin();
	if (progData.numOfDrawn > (*pos).quota) return FALSE;
	return TRUE;
}

int Tapp::load_progData (HWND hwnd)
{
	set_default (m_progData);

	WCHAR userFolder [MAX_PATH] = {0};
	WCHAR dataFolder [MAX_PATH] = {0};
	WCHAR file       [MAX_PATH] = {0};
	WCHAR msg        [MAX_MSG]  = {0};

	Tfuns::get_appDataDirectory (userFolder, g_app.m_osVer);
	PathCombine (dataFolder, userFolder, L"518cj");
	PathCombine (file, dataFolder, L"抽奖进度(勿删).dat");

	if (!PathIsDirectory(dataFolder)) {
		SetFileAttributes (dataFolder, FILE_ATTRIBUTE_NORMAL);
		DeleteFile (dataFolder);
	}

	BOOL bLoadTmp=FALSE;
REDO:
	if (PathIsDirectory(file)) Tfuns::del_folder(file);

	WIN32_FILE_ATTRIBUTE_DATA fad = {0};
	if (GetFileAttributesEx(file, GetFileExInfoStandard, &fad)) {
		if ((fad.nFileSizeHigh != 0) || (fad.nFileSizeLow/1024.0/1024.0 >= 64.0)) {
			SetFileAttributes (file, FILE_ATTRIBUTE_NORMAL);
			DeleteFile (file);
		}
		if (fad.nFileSizeLow == 0) return 0;
	}

	if (!PathFileExists(file)) {
		if (!bLoadTmp) {
			lstrcat (file, L".tmp");
			bLoadTmp = TRUE;
			goto REDO;
		}
		else return 0;
	}

	FILE* f = _wfopen (file, L"rb");
	if (!f) {
		if (EACCES == errno) swprintf (msg, L"读文件失败:\n%s\n\n%S\n(请检查读写权限)", file, strerror(errno));
		else swprintf (msg, L"读文件失败:\n%s\n\n%S", file, strerror(errno));
		MessageBox (hwnd, msg, g_app_title, MB_OK | MB_ICONERROR);
		return -1;
	}

	int cb=0;
	int n,i;
	if (!fread(&m_progData.bPhotoMode, sizeof(m_progData.bPhotoMode), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.bPhotoMode);
	if (!fread(m_progData.photoFolder, sizeof(m_progData.photoFolder), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.photoFolder);
	if (!fread(&m_progData.state, sizeof(m_progData.state), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.state);
	if (!fread(&m_progData.bExtra, sizeof(m_progData.bExtra), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.bExtra);
	if (!fread(&m_progData.numOfDrawn, sizeof(m_progData.numOfDrawn), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.numOfDrawn);
	if (!fread(&m_progData.numOfRolling, sizeof(m_progData.numOfRolling), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.numOfRolling);
	if (!fread(m_progData.cxrsOfRolling, sizeof(m_progData.cxrsOfRolling), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.cxrsOfRolling);
	if (!fread(m_progData.flagsOfDel, sizeof(m_progData.flagsOfDel), 1, f)) goto FREAD_FAIL;
	cb += sizeof(m_progData.flagsOfDel);

	m_progData.photoFolder [MAX_PATH-1] = 0;
	for (i=0; i<MAX_DRAW_NUM_ONCE; i++) 
		m_progData.cxrsOfRolling[i][MAX_CXR_NAME-1] = 0;
	if (m_progData.numOfDrawn<0 || m_progData.numOfDrawn>MAX_CXR_NUM) goto DATA_ERR;
	if (m_progData.numOfRolling<0 || m_progData.numOfRolling>MAX_DRAW_NUM_ONCE) goto DATA_ERR;

	n = 0;
	if (!fread(&n, sizeof(n), 1, f)) goto FREAD_FAIL;
	cb += sizeof(n);
	if (n>MAX_AWARD_NUM || n<1) goto DATA_ERR;
	for (i=1; i<=n; i++) 
	{
		award_t award;
		if(!fread(award.award, sizeof(award.award), 1, f)) goto FREAD_FAIL;
		cb += sizeof(award.award);
		if(!fread(&award.quota, sizeof(award.quota), 1, f)) goto FREAD_FAIL;
		cb += sizeof(award.quota);
		if(!fread(&award.per, sizeof(award.per), 1, f)) goto FREAD_FAIL;
		cb += sizeof(award.per);
		if(!fread(&award.col, sizeof(award.col), 1, f)) goto FREAD_FAIL;
		cb += sizeof(award.col);
		if(!fread(award.prize, sizeof(award.prize), 1, f)) goto FREAD_FAIL;
		cb += sizeof(award.prize);
		if(!fread(award.pic, sizeof(award.pic), 1, f)) goto FREAD_FAIL;
		cb += sizeof(award.pic);

		award.award [MAX_AWARD_NAME-1] = 0;
		award.prize [MAX_PRIZE_DESC-1] = 0;
		award.pic   [MAX_PATH-1] = 0;

		if (award.quota < 1 || award.quota > MAX_CXR_NUM) goto DATA_ERR;
		if (award.per < 1 || award.per > MAX_DRAW_NUM_ONCE) goto DATA_ERR;
		if (award.col < 1 || award.col > MAX_COL_NUM) goto DATA_ERR;
		if (award.per > award.quota) goto DATA_ERR;
		if (award.col > award.per) goto DATA_ERR;

		int m = 0;
		int j = 0;
		if (!fread(&m, sizeof(m), 1, f)) goto FREAD_FAIL;
		cb += sizeof(m);
		if (m<0 || m>MAX_CXR_NUM) goto DATA_ERR;
		for (j=0; j<m; j++) 
		{
			CXR_t cxr = {0};
			if (!fread(&cxr, sizeof(cxr), 1, f)) goto FREAD_FAIL;
			cb += sizeof(cxr);
			cxr.cxr [MAX_CXR_NAME-1] = 0;
			award.whites.push_back(cxr);
		}

		m = 0;
		if (!fread(&m, sizeof(m), 1, f)) goto FREAD_FAIL;
		cb += sizeof(m);
		if (m<0 || m>MAX_CXR_NUM) goto DATA_ERR;
		for (j=0; j<m; j++) 
		{
			CXR_t cxr = {0};
			if (!fread(&cxr, sizeof(cxr), 1, f)) goto FREAD_FAIL;
			cb += sizeof(cxr);
			cxr.cxr [MAX_CXR_NAME-1] = 0;
			award.blacks.push_back(cxr);
		}

		m_progData.awards.push_back(award);
	}


	n = 0;
	if (!fread(&n, sizeof(n), 1, f)) goto FREAD_FAIL;
	cb += sizeof(n);
	if (n>MAX_CXR_NUM || n<0) goto DATA_ERR;
	for (i=1; i<=n; i++) {
		CXR_t cxr = {0};
		if (!fread(&cxr, sizeof(cxr), 1, f)) goto FREAD_FAIL;
		cb += sizeof(cxr);
		cxr.cxr [MAX_CXR_NAME-1] = 0;
		m_progData.cxrs.push_back(cxr);
	}


	n=0;
	if (!fread(&n, sizeof(n), 1, f)) goto FREAD_FAIL;
	cb += sizeof(n);
	if (n<0 || n>MAX_AWARD_NUM*2) goto DATA_ERR;
	for (i=1; i<=n; i++) 
	{
		winnersOfAward_t winnersOfAward;
		if (!fread(winnersOfAward.award, sizeof(winnersOfAward.award), 1, f)) goto FREAD_FAIL;
		cb += sizeof(winnersOfAward.award);
		winnersOfAward.award [MAX_AWARD_NAME-1] = 0;

		int m = 0;
		if (!fread(&m, sizeof(m), 1, f)) goto FREAD_FAIL;
		cb += sizeof(m);
		if (m < 0) goto DATA_ERR;
		for (int j=1; j<=m; j++) 
		{
			CXR_t cxr = {0};
			if (!fread(&cxr, sizeof(cxr), 1, f)) goto FREAD_FAIL;
			cb += sizeof(cxr);
			cxr.cxr [MAX_CXR_NAME-1] = 0;
			winnersOfAward.winners.push_back(cxr);
		}
		m_progData.result.push_back (winnersOfAward);
	}

	fclose(f); f=NULL;
	if (fad.nFileSizeLow != cb) goto DATA_ERR;
	if (!check_progData(m_progData)) goto DATA_ERR;

	if (bLoadTmp) 
	{
		WCHAR file_new [MAX_PATH] = {0};
		lstrcpy (file_new, file);
		PathRemoveExtension (file_new);
		if (_wrename(file, file_new) != 0) {
			swprintf (msg, L"\"抽奖进度\"载入失败:\n%s\n\n%S\n(请检查读写权限)", file, strerror(errno));
			goto RENAME_FAIL;
		} 
		SetFileAttributes (file, FILE_ATTRIBUTE_NORMAL);
		DeleteFile (file);
	}

	return 1;

FREAD_FAIL:
	if (feof(f)) swprintf (msg, L"\"抽奖进度\"载入失败:\n%s\n\n文件内容有错误", file);
	else swprintf (msg, L"\"抽奖进度\"载入失败:\n%s\n\n%S", file, strerror(errno));
DATA_ERR:
	if (f) fclose (f);
	if (*msg == 0) swprintf (msg, L"\"抽奖进度\"载入失败:\n%s\n\n文件内容有错误", file);
RENAME_FAIL:
	set_default (m_progData);
	MessageBox (hwnd, msg, g_app_title, MB_OK | MB_ICONERROR);
	return -1;
}


int Tapp::save_progData (progData_t& progData, WCHAR* msg)
{
	WCHAR userFolder [MAX_PATH] = {0};
	WCHAR dataFolder [MAX_PATH] = {0};
	WCHAR file       [MAX_PATH] = {0};

	Tfuns::get_appDataDirectory (userFolder, g_app.m_osVer);
	PathCombine (dataFolder, userFolder, L"518cj");
	PathCombine (file, dataFolder, L"抽奖进度(勿删).dat.tmp");

	if (!PathIsDirectory(dataFolder)) {
		SetFileAttributes (dataFolder, FILE_ATTRIBUTE_NORMAL);
		DeleteFile (dataFolder);
	}
	if (PathIsDirectory(file)) Tfuns::del_folder(file);
	else SetFileAttributes (file, FILE_ATTRIBUTE_NORMAL);

	Tfuns::create_dirs (file, FALSE);

	FILE* f = _wfopen (file, L"wb");
	if (!f) {
		if (EACCES == errno) swprintf (msg, L"无法写入文件 %s\n\n%S\n(请检查读写权限)", file, strerror(errno));
		else swprintf (msg, L"无法写入文件 %s\n\n%S", file, strerror(errno));
		return 0;
	}

	if (!fwrite(&(progData.bPhotoMode), sizeof(progData.bPhotoMode), 1, f)) goto ERR;
	if (!fwrite(progData.photoFolder, sizeof(progData.photoFolder), 1, f)) goto ERR;
	if (!fwrite(&(progData.state), sizeof(progData.state), 1, f)) goto ERR;
	if (!fwrite(&(progData.bExtra), sizeof(progData.bExtra), 1, f)) goto ERR;
	if (!fwrite(&(progData.numOfDrawn), sizeof(progData.numOfDrawn), 1, f)) goto ERR;
	if (!fwrite(&(progData.numOfRolling), sizeof(progData.numOfRolling), 1, f)) goto ERR;
	if (!fwrite(progData.cxrsOfRolling, sizeof(progData.cxrsOfRolling), 1, f)) goto ERR;
	if (!fwrite(progData.flagsOfDel, sizeof(progData.flagsOfDel), 1, f)) goto ERR;

	{
		int n = progData.awards.size();
		if (!fwrite(&n, sizeof(n), 1, f)) goto ERR;
		list<award_t>::iterator pos = progData.awards.begin ();
		while (pos != progData.awards.end()) 
		{
			if (!fwrite((*pos).award, sizeof((*pos).award), 1, f)) goto ERR;
			if (!fwrite(&(*pos).quota, sizeof((*pos).quota), 1, f)) goto ERR;
			if (!fwrite(&(*pos).per, sizeof((*pos).per), 1, f)) goto ERR;
			if (!fwrite(&(*pos).col, sizeof((*pos).col), 1, f)) goto ERR;
			if (!fwrite((*pos).prize, sizeof((*pos).prize), 1, f)) goto ERR;
			if (!fwrite((*pos).pic, sizeof((*pos).pic), 1, f)) goto ERR;

			int m = (*pos).whites.size();
			if (!fwrite(&m, sizeof(m), 1, f)) goto ERR;
			list<CXR_t>::iterator p = (*pos).whites.begin();
			while (p != (*pos).whites.end()) {
				if (!fwrite(&(*p), sizeof(CXR_t), 1, f)) goto ERR;
				p++;
			}

			m = (*pos).blacks.size();
			if (!fwrite(&m, sizeof(m), 1, f)) goto ERR;
			p = (*pos).blacks.begin();
			while (p != (*pos).blacks.end()) {
				if (!fwrite(&(*p), sizeof(CXR_t), 1, f)) goto ERR;
				p++;
			}

			pos++;
		}
	}

	{
		int n = progData.cxrs.size();
		if (!fwrite(&n, sizeof(n), 1, f)) goto ERR;
		list<CXR_t>::iterator pos = progData.cxrs.begin ();
		while (pos != progData.cxrs.end()) {
			if (!fwrite(&(*pos), sizeof(CXR_t), 1, f)) goto ERR;
			pos++;
		}
	}

	{
		int n = progData.result.size();
		if (!fwrite(&n, sizeof(n), 1, f)) goto ERR;
		list<winnersOfAward_t>::iterator pos = progData.result.begin ();
		while (pos != progData.result.end()) 
		{
			if (!fwrite((*pos).award, sizeof((*pos).award), 1, f)) goto ERR;
			int m = (*pos).winners.size();
			if (!fwrite(&m, sizeof(m), 1, f)) goto ERR;
			list<CXR_t>::iterator p = (*pos).winners.begin();
			while (p != (*pos).winners.end()) {
				if (!fwrite(&(*p), sizeof(CXR_t), 1, f)) goto ERR;
				p++;
			}
			pos++;
		}
	}

	fflush (f);
	fclose (f);

	{
		WCHAR file_new [MAX_PATH] = {0};
		lstrcpy (file_new, file);
		PathRemoveExtension (file_new);
		SetFileAttributes (file_new, FILE_ATTRIBUTE_NORMAL);
		if (PathFileExists(file_new) && _wremove(file_new) != 0) {
 			swprintf (msg, L"无法写入文件 %s\n\n%S\n(请检查读写权限)", file_new, strerror(errno));
			return 0;
		}
		if (_wrename(file, file_new) != 0) {
 			swprintf (msg, L"无法写入文件 %s\n\n%S\n(请检查读写权限)", file, strerror(errno));
			return 0;
		}
	}
	SetFileAttributes (file, FILE_ATTRIBUTE_NORMAL);
	DeleteFile (file);
	return 1;

ERR:
	swprintf (msg, L"无法写入文件 %s\n\n%S", file, strerror(errno));
	if (f) fclose (f);
	return 0;
}


0

回复列表 (共1个回复)

沙发

什么牌子的手术台好手术无影灯 妇科手术台在什么价位手术台 外科手术灯都有哪些类型和样式手术床 无影手术灯 与普通照明灯的区别是什么啊无影灯 外科手术灯是由什么组成的电动手术台 手术灯的灯头有几种?电动手术床 医用无影灯与普通灯有什么区别综合手术台 上海北京用的最多的手术灯是什么手术室无影灯 手术室手术灯、电动床吊塔怎么选?多功能电动床 医用无影灯与普通灯有什么区别多功能手术台 手术灯为什么没有影子?医用手术台 医生手术头灯哪种好医用手术床 手术无影灯是什么?医用无影灯 手术台上方为什么有强灯?医用吊塔 LED手术灯如何调整高度LED手术灯 led手术灯与整体反射手术灯之间的优势是什么LED无影灯 什么叫手术台次LED手术无影灯 上手术台的专业是什么医用手术无影灯 上手术台的专业是什么医用电动手术台 液压手术床跟电机手术床有什么区别?液压手术台 上手术台的专业是什么多功能手术台 手术床与麻醉医生比例电动妇科手术台 

我来回复

您尚未登录,请登录后再回复。点此登录或注册