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

📄 snimacfajl.cpp

📁 pc loader for 8051 based microcomputers
💻 CPP
字号:
// SnimacFajl.cpp: implementation of the CSnimacFajl class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SnimacFajl.h"

#include "Win32File.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSnimacFajl::CSnimacFajl(const std::string& nazivFajla)
: pFajl_m(new CFile())
, nazivFajla_m(nazivFajla)
, spoljniCFile_m(false)
, otvoriZatvori_m(true)
{
}

CSnimacFajl::CSnimacFajl(CFile* pFajl)
: pFajl_m(pFajl)
, spoljniCFile_m(true)
, otvoriZatvori_m(false)
{
    std::string pomStr(LPCTSTR(pFajl->GetFileName()));
    nazivFajla_m = pomStr;
}

CSnimacFajl::~CSnimacFajl()
{
    if (!spoljniCFile_m) {
        delete pFajl_m;
    }
}

bool CSnimacFajl::Start(std::string& opis)
{
    // Ako nije potrebno otvaranje, ne radi nista
    if (!otvoriZatvori_m) return true;

    if (!ProveriFajlPtr(opis)) return false;

    bool bOK = false;
    CFileException e;
    if (pFajl_m->Open(nazivFajla_m.c_str(), CFile::modeCreate | CFile::modeWrite, &e)) {
        bOK = true;
    }
    else {
        opis = CWin32File::ExceptionToTxt(e, "unknown error in Open");
    }
    return bOK;
}

bool CSnimacFajl::Stop(std::string& opis)
{
    // Ako nije potrebno zatvaranje, ne radi nista
    if (!otvoriZatvori_m) return true;

    if (!ProveriFajlPtr(opis)) return false;

    bool bOK = false;
    std::string defaultOpis = "unknown error in Close";
    try {
        pFajl_m->Close();
        bOK = true;
    }
    catch (CFileException* e) {
        opis = CWin32File::ExceptionToTxt(*e, defaultOpis);
        e->Delete();
    }
    catch (...) {
        opis = defaultOpis;
    }
    return bOK;
}

//////////////////////////////////////////////////////////////////////
// Pomocne funkcije
//////////////////////////////////////////////////////////////////////

bool CSnimacFajl::ProveriFajlPtr(std::string& opis)
{
    if (pFajl_m == 0){
        opis = TXT_NULL_PTR;
        return false;
    }
    return true;
}

// tekstovi
const std::string CSnimacFajl::TXT_NULL_PTR = "null file pointer";

⌨️ 快捷键说明

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