⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datastreamdlg.cpp

📁 对数据进行一些流方面的操作
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// DataStreamDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DataStream.h"
#include "DataStreamDlg.h"
#include "BitmapEx.h"
#include "zstream.h"
#include "GetDataDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDataStreamDlg dialog

CDataStreamDlg::CDataStreamDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDataStreamDlg::IDD, pParent)
{
	 m_strDocFile="";
	 m_strPreName="";
	 m_iTotalSize=0;
	 m_iCurPos=-1;
     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDataStreamDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDataStreamDlg)
	DDX_Control(pDX, IDC_LIST, m_list);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDataStreamDlg, CDialog)
	//{{AFX_MSG_MAP(CDataStreamDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_READ, OnRead)
	ON_BN_CLICKED(IDC_EXTRA, OnExtra)
	ON_BN_CLICKED(IDC_PRE, OnPre)
	ON_BN_CLICKED(IDC_NEXT, OnNext)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_NEWZIP, OnNewzip)
	ON_BN_CLICKED(IDC_ADDZIP, OnAddzip)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_FOLDER, OnFolder)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDataStreamDlg message handlers

BOOL CDataStreamDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDataStreamDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDataStreamDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	//图片显示
	CDialog::OnPaint();
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDataStreamDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDataStreamDlg::OnRead() 
{
	////得到要保存的压缩数据文件名
	char szFilter[] = "数据文件 (*.dat)|*.dat||";
	CFileDialog dlg(TRUE, "*.dat", NULL, OFN_HIDEREADONLY |
		OFN_OVERWRITEPROMPT, szFilter );
	if (dlg.DoModal() == IDCANCEL) return;
	CString strDataName=dlg.GetPathName();
	if(strDataName.GetLength()==0)return;
	LoadBmp(strDataName);
}

void CDataStreamDlg::WriteFile(LPCSTR sDataName)
{
	CString strDataName=sDataName;
	if(strDataName.GetLength()==0)return;
	open_StgDoc(strDataName);
	CFile f;
	byte * lpBuf;
	int iSize=0;
	CString strName,sName,str,strINIFileName;
 
	///////////////////////
    //读文件写入压缩流
	CWnd* pWnd=GetDlgItem(IDC_SNAME);
	CString strPreName=m_strPreName;
	if(strPreName.GetLength()>0)strPreName+="_";
	int n=m_files.GetSize();
	if(n<=0)return;
	//把文件列表写入配置文件中
	CStdioFile fINI;
	strINIFileName=strDataName;
    strINIFileName.Replace(".dat",".ini");
	int iCurItem=GetPrivateProfileInt("totals","number",0,strINIFileName);
	if(!iCurItem)
	{   //配置文件不存在就创建
		if(!fINI.Open(strINIFileName,CFile::modeWrite|CFile::modeCreate))
			return;
		str.Format("[Totals]\n");
		fINI.WriteString(str);
		str.Format("Number=%d\n",n);
		fINI.WriteString(str);
		str.Format("[Stream]\n");
		fINI.WriteString(str);
		iCurItem=0;
	}
	else
		fINI.Open(strINIFileName,CFile::modeWrite);
	fINI.SeekToEnd();
	////
	int iPos;
	SetRedraw (FALSE);
	m_list.ResetContent();
	for(int i=0;i<n;i++)
	{
		strName=m_files.GetAt(i);
		str.Format("压缩完成:%s",strName);
        m_list.AddString(str);
		f.Open(strName,CFile::modeRead,NULL);
		iSize=f.GetLength();
		lpBuf=(byte *)malloc(iSize);
		f.Read(lpBuf, iSize);
		sName.Format("%s%d",strPreName,i);
		write_stream(sName,lpBuf,iSize);
		free(lpBuf);
		
		str.Format("[%d]\n",iCurItem+i);
		fINI.WriteString(str);
		
		str.Format("sName=%s\n",sName);
		fINI.WriteString(str);
		
		strName=m_files.GetAt(i);
		iPos=strName.ReverseFind('\\');
		strName=strName.Mid(iPos+1);
		str.Format("fName=%s\n",strName);
		fINI.WriteString(str);
		
		str.Format("iSize=%d\n",iSize);
		fINI.WriteString(str);
	}
	str.Format("总共压缩 %d 个文件。",n);
	m_list.AddString(str);
	SetRedraw (TRUE);
    Invalidate();
 	fINI.Close();
	close_StgDoc();	
	str.Format("%d",iCurItem+n);
	WritePrivateProfileString("totals","number",str,strINIFileName);
	
}

void CDataStreamDlg::OnExtra() 
{
	////得到要保存的压缩数据文件名
	char szFilter[] = "数据文件 (*.dat)|*.dat||";
	CFileDialog dlg(TRUE, "*.dat", NULL, OFN_HIDEREADONLY |
		OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT, szFilter );
	if (dlg.DoModal() == IDCANCEL) return;
	CString strDataName=dlg.GetPathName();
	if(strDataName.GetLength()==0)return;
	open_StgDoc(strDataName);
	CString strIniFile,strPath;
	int iPos=strDataName.ReverseFind('.');
    strPath=strDataName.Left(iPos);	
	CreateDirectory(strPath,NULL);
	strPath+="\\";
	strIniFile=strDataName;
    strIniFile.Replace(".dat",".ini");
	
	////////读取配置文件得到流对应的文件名
	CString sName,fName,str;
	char szValue[256];
	int n=GetPrivateProfileInt("totals","number",0,strIniFile);
    if(!n) return;
	DWORD iSize=0;
	CComPtr<IStream> pStream=NULL;
	m_list.ResetContent();
	for(int i=0;i<n;i++)
	{              
		str.Format("%d",i);
		GetPrivateProfileString(str,"fName",NULL,
			szValue,sizeof(szValue),strIniFile);
		fName = strPath+szValue;
	    m_list.AddString("解压完成:"+fName);
 
		GetPrivateProfileString(str,"sName",NULL,
			szValue,sizeof(szValue),strIniFile);
		sName = szValue;
		iSize=GetPrivateProfileInt(str,"iSize",0,strIniFile);
		stream2file(sName,fName,iSize);
	 /*	/////////////////////
		pStream=read_stream(sName,iSize);
		if(pStream == NULL)
		{
			CString str;
			str.Format("数据流%s无法打开!",sName);
			MessageBox(str);
			continue;
		}
		ULONG uSize=iSize+12;
		byte * lpBuf;
		lpBuf=(byte *)malloc(uSize);
		ULONG pcbRead=0;
		int rst=pStream->Read(lpBuf,uSize,&pcbRead);
		CFile f;
		f.Open(fName,CFile::modeWrite|CFile::modeCreate,NULL);
		f.Write(lpBuf,pcbRead);
		f.Close();
		free(lpBuf);*/
	}
	str.Format("总共还原 %d 个文件。",n);
	m_list.AddString(str);
	close_StgDoc();
}


void CDataStreamDlg::OnPre() 
{
	if(m_iCurPos<1)return;
	m_iCurPos--;
	Invalidate();
	
}

void CDataStreamDlg::OnNext() 
{
	if(m_iCurPos>m_iTotalSize-2)return;
	m_iCurPos++;
	Invalidate();
}



void CDataStreamDlg::DeletContents()
{

}

void CDataStreamDlg::OnDestroy() 
{
	DeletContents();
	CDialog::OnDestroy();
}

void CDataStreamDlg::OnNewzip() 
{
	////得到要保存的压缩数据文件名
	char szFilter[] = "数据文件 (*.dat)|*.dat||";
	CFileDialog dlg( FALSE, "*.dat", NULL, OFN_HIDEREADONLY |

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -