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

📄 mmsstream.c

📁 JPEG解压软件,包含PC端的测试程序,程序结构比较清晰
💻 C
字号:
#include <stdio.h>
//#include "mmsplat.h"
#include "mmsDef.h"
#include "mmsStream.h"

#include <windows.h>


typedef struct tag_stream {
	FILE * fp;
	MChar name[128];
	MChar path[128];
}MMS_STREAM;



HMSTREAM	Stream_Open(MPCChar szLocation, MPCChar szID) {
	if (!szLocation || !szID) 
		return MNull;
	else {
		FILE * fp = MNull;
		MMS_STREAM * mms_stream = MNull;
		MChar full_path[256];
		strcpy(full_path , szLocation);
		strcat(full_path , szID);
		fp = fopen(full_path , "rb+");
		if (!fp)
			return MNull;
		mms_stream = (MMS_STREAM *)malloc(sizeof(MMS_STREAM));
		memset(mms_stream , 0 , sizeof(MMS_STREAM));
		mms_stream->fp = fp;
		strcpy(mms_stream->path , szLocation);
		strcpy(mms_stream->name , szID);
		return mms_stream; 
	}
}

MBool		Stream_Close(HMSTREAM hStream) {
	MMS_STREAM * mms_stream = (MMS_STREAM *)hStream;
	if ( mms_stream) {
		fclose(mms_stream->fp);
		free(mms_stream);
		return MTrue;
	}
	else {
		return MFalse;
	}
}

MPCChar	Stream_GetID(HMSTREAM hStream) {
	if (hStream) {
		return ((MMS_STREAM *)hStream)->name; 
	}
	else
		return MNull;
}


MPCChar	Stream_GetLocation(HMSTREAM hStream) {
	if (hStream) {
		return ((MMS_STREAM *)hStream)->path; 
	}
	else
		return MNull;

}


HMSTREAM	Stream_Create(MPCChar szLocation, MPCChar szID) {
	if (!szLocation || !szID) 
		return MNull;
	else {
		FILE * fp = MNull;
		MMS_STREAM * mms_stream = MNull;
		MChar full_path[256];
		strcpy(full_path , szLocation);
		strcat(full_path , szID);
		fp = fopen(full_path , "wb+");
		if (!fp)
			return MNull;
		mms_stream = (MMS_STREAM *)malloc(sizeof(MMS_STREAM));
		memset(mms_stream , 0 , sizeof(MMS_STREAM));
		mms_stream->fp = fp;
		strcpy(mms_stream->path , szLocation);
		strcpy(mms_stream->name , szID);
		return mms_stream; 
	}

}

MBool		Stream_Destroy(MPCChar szLocation, MPCChar szID) {
	MChar full_path[256];
	strcpy(full_path , szLocation);
	strcat(full_path , szID);
	return DeleteFile(full_path);
}

MBool		Stream_Rename(MPCChar szLocation, MPCChar szID,MPCChar szNewLocation, MPCChar szNewID) {
	//MChar old_full_path[256] , new_full_path[256];
	int ret;
	//strcpy(old_full_path , szLocation);
	//strcat(old_full_path , szID);
	//strcpy(new_full_path , szNewLocation);
	//strcat(new_full_path , szNewID);
	ret = rename(szID , szNewID);
	return ret=0?MTrue:MFalse;
	
}

long		Stream_GetSize( HMSTREAM hStream ) {
	MMS_STREAM * mms_stream = (MMS_STREAM *)hStream;
	if ( mms_stream) {
		long current_pos , total_len;
		current_pos = ftell(mms_stream->fp);
		//goto file end
		fseek(mms_stream->fp , 0 ,SEEK_END);
		total_len = ftell(mms_stream->fp);
		//goto current pos
		fseek(mms_stream->fp , current_pos , SEEK_SET);
		return total_len;
	}
	else {
		return -1;
	}


}

long		Stream_GetSizeEx(MPCChar szLocation, MPCChar szID) {
	MChar full_path[256];
	FILE * fp = MNull;
	strcpy(full_path , szLocation);
	strcat(full_path , szID);
	fp = fopen(full_path , "rb");
	if (!fp) return 0;
	fseek(fp , 0 , SEEK_END);
	return ftell(fp);
}



long		Stream_Read(HMSTREAM hStream, void* pBuf, long size) {
	if (hStream) {
		return fread(pBuf , 1 , size , ((MMS_STREAM *)hStream)->fp); 
	}
	else
		return -1;

}

long		Stream_Write(HMSTREAM hStream, void* pBuf, long size) {
	if (hStream) {
		return fwrite(pBuf , 1 ,size , ((MMS_STREAM *)hStream)->fp); 
	}
	else
		return -1;
	
}

MBool		Stream_Flush(HMSTREAM hStream) {
	return MTrue;
}


long		Stream_Seek(HMSTREAM hStream, short start, long offset) {
	if (hStream) {
		return fseek(((MMS_STREAM *)hStream)->fp ,offset , start); 
	}
	else
		return -1;
	
}

long		Stream_Tell(HMSTREAM hStream) {
	if (hStream) {
		return ftell(((MMS_STREAM *)hStream)->fp); 
	}
	else
		return -1;

}

⌨️ 快捷键说明

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