Ejemplo n.º 1
0
//ファイル保存を開始する
//戻り値:
// TRUE(成功)、FALSE(失敗)
//引数:
// fileName				[IN]保存ファイルフルパス(必要に応じて拡張子変えたりなど行う)
// overWriteFlag		[IN]同一ファイル名存在時に上書きするかどうか(TRUE:する、FALSE:しない)
// createSize			[IN]入力予想容量(188バイトTSでの容量。即時録画時など総時間未定の場合は0。延長などの可能性もあるので目安程度)
BOOL CWriteMain::_StartSave(
	LPCWSTR fileName,
	BOOL overWriteFlag,
	ULONGLONG createSize
	)
{
	this->savePath = L"";

	wstring errMsg = L"";
	DWORD err = 0;

	wstring recFilePath = fileName;
	if( overWriteFlag == TRUE ){
		_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
		this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
		if( this->file == INVALID_HANDLE_VALUE ){
			err = GetLastError();
			GetLastErrMsg(err, errMsg);
			_OutputDebugString(L"★_StartSave Err:0x%08X %s", err, errMsg.c_str());
			if( GetNextFileName(fileName, recFilePath) == TRUE ){
				_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
				this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
			}
		}
	}else{
		_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
		this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
		if( this->file == INVALID_HANDLE_VALUE ){
			err = GetLastError();
			GetLastErrMsg(err, errMsg);
			_OutputDebugString(L"★_StartSave Err:0x%08X %s", err, errMsg.c_str());
			if( GetNextFileName(fileName, recFilePath) == TRUE ){
				_OutputDebugString(L"★_StartSave CreateFile:%s", recFilePath.c_str());
				this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
			}
		}
	}
	if( this->file == INVALID_HANDLE_VALUE ){
		err = GetLastError();
		GetLastErrMsg(err, errMsg);
		_OutputDebugString(L"★_StartSave Err:0x%08X %s", err, errMsg.c_str());
		this->file = NULL;
		return FALSE;
	}

	//ディスクに容量を確保
	if( createSize > 0 ){
		LARGE_INTEGER stPos;
		stPos.QuadPart = createSize;
		SetFilePointerEx( this->file, stPos, NULL, FILE_BEGIN );
		SetEndOfFile( this->file );
		CloseHandle( this->file );
		this->file = _CreateFile2( recFilePath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
		SetFilePointer( this->file, 0, NULL, FILE_BEGIN );
	}

	this->savePath = recFilePath;

	return TRUE;
}
Ejemplo n.º 2
0
DWORD CDirectoryName::GetNextFileName(CStrClass* pFileNameOut)
{
	if(m_bReturnSelf == FALSE)
	{
		*pFileNameOut = GetFullPathName();
		m_bReturnSelf = TRUE;
		return GETNEXTFILENAME_DIRECTORY;
	}

	if(m_Iter == m_ChildList.end())
		return GETNEXTFILENAME_END;

	CFileName* pChild = *m_Iter;
	if(pChild->IsDirectory())
	{
		DWORD rt;
		if( rt = ((CDirectoryName*)pChild)->GetNextFileName(pFileNameOut) )
			return rt;
		else
		{
			++m_Iter;
			return GetNextFileName(pFileNameOut);			
		}
	}

	*pFileNameOut = pChild->GetFullPathName();
	++m_Iter;
	return GETNEXTFILENAME_FILE;
}
Ejemplo n.º 3
0
int GetNewFace(INPUT_DESC *input, int nDirection)
{
	char strFileName[128];

	if (nDirection == DIRECTION_FORWARD)
		g_nPoseID++;
	else
		g_nPoseID--;


	while (GetNextFileName(strFileName, nDirection))
		;

	if (ReadFaceInput(input, strFileName))
		return (-1);
			
	check_input_bounds (input, input->wx + input->ww/2, input->wy + input->wh/2);
	input->up2date = 0;
	update_input_neurons (input);
	update_input_image (input);

	input->green_cross_x = g_nLeftEyeX;
	input->green_cross_y = g_nLeftEyeY;
	g_nPos = 0;
	
	return (0);
}
Ejemplo n.º 4
0
void init_face_recog(INPUT_DESC *input)
{
#ifndef NO_INTERFACE
	int x, y;
#endif
	char strFileName[128];

	g_nLeftEyeX = 0;
	g_nLeftEyeY = 0;
	g_nRightEyeX = 0;
	g_nRightEyeY = 0;
	g_nNoseX = 0;
	g_nNoseY = 0;
	g_nMouthX = 0;
	g_nMouthY = 0;

	g_nPoseID = POSE_MIN;
	g_nPersonID = MIN_PERSON_ID;
	g_nFacePart = EYE;
	g_nStatus = MOVING_PHASE;

	g_nTotalTested = 0;
	g_nCorrect = 0;
	g_nNoOne = 0;
	
	make_input_image_face_recog (input, IMAGE_WIDTH, IMAGE_HEIGHT);

	// Le a primeira imagem
	if (!GetNextFileName(strFileName, DIRECTION_FORWARD))
	{
		ReadFaceInput(input, strFileName);
	}

	input->green_cross = 1;
	input->green_cross_x = g_nLeftEyeX;
	input->green_cross_y = g_nLeftEyeY;
	g_nPos = 0;
		
	input->up2date = 0;
	update_input_neurons (input);

#ifndef NO_INTERFACE
	glutInitWindowSize (input->ww, input->wh);
	if (read_window_position (input->name, &x, &y))
		glutInitWindowPosition (x, y);
	else
		glutInitWindowPosition (-1, -1);
	input->win = glutCreateWindow (input->name);

	glGenTextures (1, (GLuint *)(&(input->tex)));
	input_init (input);
	glutReshapeFunc (input_reshape);
	glutDisplayFunc (input_display);
	glutKeyboardFunc (keyboard);
	glutPassiveMotionFunc (input_passive_motion);
	glutMouseFunc (input_mouse);
#endif
}
Ejemplo n.º 5
0
int GetNewDocument(INPUT_DESC *input, int nDirection)
{
	char strFileName[128];

	while (GetNextFileName(strFileName, nDirection))
		;

	if (ReadDocumentInput(input, strFileName))
		return (-1);
			
	check_input_bounds (input, input->wx + input->ww/2, input->wy + input->wh/2);

	return (0);
}
Ejemplo n.º 6
0
NEURON_OUTPUT GetDoc (PARAM_LIST *pParamList)
{
	NEURON_OUTPUT output;
	char strFileName[256];
	int nDoc;
	int mode;
	int nDirection;
	int first_access; 

	nDoc = pParamList->next->param.ival;
	mode = pParamList->next->next->param.ival;
	first_access = pParamList->next->next->next->param.ival;
	
	if(mode == LINEAR_MODE)
	{
		if(first_access)
		{
			g_nDocNumber = nDoc;
			nDirection = NO_DIRECTION;
		}
		else
			nDirection = DIRECTION_FORWARD;
	}
	else    //RANDOM_MODE
	{
		g_nDocNumber = (random() % DOC_MAX) + 1;
		nDirection = NO_DIRECTION;
	}
	
	while (GetNextFileName(strFileName, nDirection))
		;
	
	if (ReadDocumentInput(&document, strFileName))
	{
		printf ("Error: Cannot read document (GetDoc).\n");
		output.ival = -1;
		return (output);
	}
	
	update_input_image (&document);
	check_input_bounds (&document, document.wx + document.ww/2, document.wy + document.wh/2);

	output.ival = 0;
	
	return (output);
}
Ejemplo n.º 7
0
/// Close the current file, if one is open, and open a new file for data output
bool PollOutputFile::OpenNewFile(std::string title_, int &run_num_, std::string prefix, std::string output_directory/*="./"*/, bool continueRun /*= false*/){
	CloseFile();

	// Restart the spill counter for the new file
	number_spills = 0;

	std::string filename = GetNextFileName(run_num_,prefix,output_directory,continueRun);
	output_file.open(filename.c_str(), std::ios::binary);
	if(!output_file.is_open() || !output_file.good()){
		output_file.close();
		return false;
	}

	current_filename = filename;
	get_full_filename(current_full_filename);		

	if(output_format == 0){	
		dirBuff.SetRunNumber(run_num_);
		dirBuff.Write(&output_file); // Every .ldf file gets a DIR header

		headBuff.SetTitle(title_);
		headBuff.SetDateTime();
		headBuff.SetRunNumber(run_num_);
		headBuff.Write(&output_file); // Every .ldf file gets a HEAD file header
	}
	else if(output_format == 1){
		pldHead.SetTitle(title_);
		pldHead.SetRunNumber(run_num_);
		pldHead.SetStartDateTime();
		
		// Write a blank header for now and overwrite it later
		int temp = 0;
		for(int i = 0; i < pldHead.GetBufferLength()/4; i++){
			output_file.write((char*)&temp, 4);
		}
		temp = -1;
		output_file.write((char*)&temp, 4); // Close the buffer
	}
	else{
		if(debug_mode){ std::cout << "debug: invalid output format for PollOutputFile::OpenNewFile!\n"; }
		return false;
	}

	return true;
}
Ejemplo n.º 8
0
void init_class_cnae(INPUT_DESC *input)
{
	int x, y;
	char strFileName[128];

	g_nDocNumber = DOC_MIN;

	g_nTotalTested = 0;
	g_nCorrect = 0;
	
	g_nStatus = TRAINING_PHASE;
	
	make_input_image_class_cnae (input, IMAGE_WIDTH, IMAGE_HEIGHT);

	// Le a primeira imagem
	if (!GetNextFileName(strFileName, NO_DIRECTION))
	{
		ReadDocumentInput(input, strFileName);
	}
		
	input->up2date = 0;

	glutInitWindowSize (input->ww, input->wh);
	if (read_window_position (input->name, &x, &y))
		glutInitWindowPosition (x, y);
	else
		glutInitWindowPosition (-1, -1);
	input->win = glutCreateWindow (input->name);

	glGenTextures (1, (GLuint *)(&(input->tex)));
	input_init (input);
	glutReshapeFunc (input_reshape);
	glutDisplayFunc (input_display);
	glutKeyboardFunc (keyboard);
	glutPassiveMotionFunc (input_passive_motion);
	glutMouseFunc (input_mouse);
}
Ejemplo n.º 9
0
/*
 * EditFile - read a file into text
 */
vi_rc EditFile( const char *name, bool dammit )
{
    char        *fn, **list, *currfn;
    int         i, cnt, ocnt;
    int         j, len;
    window_id   wid = NO_WINDOW;
    char        cdir[FILENAME_MAX];
    info        *ci, *il;
    bool        usedir = false;
    char        mask[FILENAME_MAX];
    bool        reset_dir;
    int         index;
#ifdef __WIN__
    char        *altname = NULL;
#endif
    vi_rc       rc;

    fn = MemAlloc( FILENAME_MAX );

    /*
     * get file name
     */
    strcpy( cdir, CurrentDirectory );
    reset_dir = false;
    name = SkipLeadingSpaces( name );
    if( name[0] == '$' ) {
        ++name;
        usedir = true;
    }
    fn[0] = '\0';
//    if( NextWord1FN( name, fn ) <= 0 )
    if( GetStringWithPossibleQuote2( &name, fn, false ) != ERR_NO_ERR ) {
        usedir = true;
        mask[0] = '*';
        mask[1] = '\0';
    }
    if( usedir ) {
        if( EditFlags.ExMode ) {
            MemFree( fn );
            return( ERR_INVALID_IN_EX_MODE );
        }
        len = strlen( fn );
        if( len > 0 ) {
            strcpy( mask, fn );
            cnt = 0;
            for( i = len; i-- > 0; ) {
                if( fn[i] == FILE_SEP ) {
                    for( j = i + 1; j <= len; j++ ) {
                        mask[j - (i + 1)] = fn[j];
                    }
                    cnt = i;
                    break;
                }
            }
            fn[cnt] = '\0';
        }
        if( fn[0] != '\0' ) {
            rc = SelectFileOpen( fn, &fn, mask, true );
        } else {
#ifdef __WIN__
            if( name[0] == '\0' ) {
                altname = MemAlloc( 1000 );
                rc = SelectFileOpen( CurrentDirectory, &altname, mask, true );
                name = GetNextFileName( altname, fn );  // if multiple, kill path
                if( isMultipleFiles( name ) ) {
                    name = GetNextFileName( name, fn ); // get 1st name
                }
            } else {
                rc = SelectFileOpen( CurrentDirectory, &fn, mask, true );
            }
#else
            rc = SelectFileOpen( CurrentDirectory, &fn, mask, true );
#endif
        }

        if( rc != ERR_NO_ERR || fn[0] == '\0' ) {
            MemFree( fn );
            SetCWD( cdir );
            return( rc );
        }
    }

    /*
     * loop through all files
     */
    rc = ERR_NO_ERR;
    EditFlags.WatchForBreak = true;
#ifdef __WIN__
    ToggleHourglass( true );
#endif
    do {
        if( IsDirectory( fn ) ) {
            if( EditFlags.ExMode ) {
                rc = ERR_INVALID_IN_EX_MODE;
                reset_dir = true;
                break;
            }
            rc = SelectFileOpen( fn, &fn, "*", false );
            if( rc != ERR_NO_ERR ) {
                reset_dir = true;
                break;
            }
            if( fn[0] == '\0' ) {
                reset_dir = true;
                rc = ERR_NO_ERR;
                break;
            }
        }
        currfn = fn;
        ocnt = cnt = ExpandFileNames( currfn, &list );
        if( !cnt ) {
            cnt = 1;
        } else {
            currfn = list[0];
        }

        /*
         * loop through all expanded files
         */
        index = 1;
        while( cnt > 0 ) {
            cnt--;
            /*
             * quit current file if ! specified, else just save current state
             */
            if( dammit ) {
                ci = InfoHead;
                if( CurrentInfo == ci ) {
                    ci = ci->next;
                }
                RemoveFromAutoSaveList();
#ifdef __WIN__
                CloseAChildWindow( current_window_id );
#else
                CloseAWindow( current_window_id );
#endif
                FreeUndoStacks();
                FreeMarkList();
                FreeEntireFile( CurrentFile );
                MemFree( DeleteLLItem( (ss **)&InfoHead, (ss **)&InfoTail,
                         (ss *)CurrentInfo ) );
                CurrentInfo = NULL;
                current_window_id = NO_WINDOW;
            } else {
                ci = CurrentInfo;
                SaveCurrentInfo();
                wid = current_window_id;
            }

            /*
             * see if new file is already being edited
             */
            SaveCurrentInfo();
            for( il = InfoHead; il != NULL; il = il->next ) {
                if( SameFile( il->CurrentFile->name, currfn ) ) {
                    break;
                }
                if( strcmp( CurrentDirectory, il->CurrentFile->home ) ) {
                    /* directory has changed -- check with full path
                     * note that this will fail if an absolute path
                     * was specified thus we do the regular check first */
                    char path[FILENAME_MAX];
                    char drive[_MAX_DRIVE];
                    char dir[_MAX_DIR];
                    char fname[_MAX_FNAME];
                    char ext[_MAX_EXT];
                    size_t path_len;

                    _splitpath( il->CurrentFile->name, drive, dir, fname, ext );
                    if( drive[0] == '\0' ) {
                        _splitpath( il->CurrentFile->home, drive, NULL, NULL, NULL );
                    }
                    strcpy( path, il->CurrentFile->home );
                    path_len = strlen( path );
                    if( path_len-- > 0 ) {
#ifdef __UNIX__
                        if( path[path_len] != FILE_SEP ) {
#else
                        if( path[path_len] != DRV_SEP && path[path_len] != FILE_SEP ) {
#endif
                            strcat( path, FILE_SEP_STR );
                        }
                    }
                    if( dir[0] == '\0' ) {
                        _splitpath( path, NULL, dir, NULL, NULL );
                    } else if( dir[0] != FILE_SEP ) {
                        char dir2[_MAX_DIR];
                        _splitpath( path, NULL, dir2, NULL, NULL );
                        strcat( dir2, dir );
                        strcpy( dir, dir2 );
                    }
                    _makepath( path, drive, dir, fname, ext );

                    if( SameFile( path, currfn ) ) {
                        break;
                    }
                }
            }

            if( il != NULL ) {
                BringUpFile( il, true );
            } else {
                /*
                 * file not edited, go get it
                */
                rc = NewFile( currfn, false );
                if( rc != ERR_NO_ERR && rc != NEW_FILE ) {
                    RestoreInfo( ci );
                    DCDisplayAllLines();
                    break;
                }
                if( !dammit ) {
                    InactiveWindow( wid );
                }
                if( EditFlags.BreakPressed ) {
                    break;
                }
            }
            if( cnt > 0 ) {
                currfn = list[index];
                index++;
            }
        }

        if( ocnt > 0 ) {
            MemFreeList( ocnt, list );
        }
        if( EditFlags.BreakPressed ) {
            ClearBreak();
            break;
        }
        name = GetNextFileName( name, fn );
    } while( *fn != '\0' );

#ifdef __WIN__
    if( altname != NULL ) {
        MemFree( altname );
    }
#endif
    MemFree( fn );

#ifdef __WIN__
    ToggleHourglass( false );
#endif
    EditFlags.WatchForBreak = false;
    if( reset_dir ) {
        SetCWD( cdir );
    }
    return( rc );

} /* EditFile */

#ifndef __WIN__

static const char *fileOpts[] =  {
    (const char *)"<F1> Go To",
    (const char *)"<F2> Quit",
    (const char *)"<F3> Save & Quit"
};

static const vi_key     fileopts_evlist[] = {
    VI_KEY( F1 ),
    VI_KEY( F2 ),
    VI_KEY( F3 ),
    VI_KEY( DUMMY )
};

/*
 * EditFileFromList - edit from file in current active list
 */
vi_rc EditFileFromList( void )
{
    int         i, tmp, j, n = 0, fcnt;
    window_id   wid;
    bool        repeat = true;
    info        *cinfo;
    char        **list, modchar;
    bool        show_lineno;
    window_info wi;
    selectitem  si;
    vi_rc       rc;

    /*
     * set up options for file list
     */
    memcpy( &wi, &extraw_info, sizeof( window_info ) );
    wi.area.x1 = 2;
    wi.area.x2 = 19;
    rc = DisplayExtraInfo( &wi, &wid, fileOpts, sizeof( fileOpts ) / sizeof( fileOpts[0] ) );
    if( rc != ERR_NO_ERR ) {
        return( rc );
    }

    while( repeat > 0 ) {

        /*
         * set up for this pass
         */
        repeat = false;
        MoveWindowToFrontDammit( wid, false );
        SaveCurrentInfo();

        /*
         * allocate a buffer for strings, add strings
         */
        list = (char **) MemAlloc( GimmeFileCount() * sizeof( char * ) );
        for( j = 0, cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next, ++j ) {
            list[j] = MemAlloc( strlen( cinfo->CurrentFile->name ) + 3 );
            if( cinfo->CurrentFile->modified ) {
                modchar = '*';
            } else {
                modchar = ' ';
            }
            MySprintf( list[j], "%c %s", modchar, cinfo->CurrentFile->name );
        }
        fcnt = j;
        tmp = filelistw_info.area.y2;
        i = filelistw_info.area.y2 - filelistw_info.area.y1 + 1;
        if( filelistw_info.has_border ) {
            i -= 2;
        }
        if( j < i ) {
            filelistw_info.area.y2 -= ( i - j );
        }
        show_lineno = true;

        /*
         * get file
         */
        if( n + 1 > j ) {
            n = j - 1;
        }
        memset( &si, 0, sizeof( si ) );
        si.wi = &filelistw_info;
        si.title = "Current Files";
        si.list = list;
        si.maxlist = j;
        si.num = n;
        si.retevents = fileopts_evlist;
        si.event = VI_KEY( DUMMY );
        si.show_lineno = show_lineno;
        si.cln = n + 1;
        si.eiw = wid;
        rc = SelectItem( &si );
        n = si.num;
        if( rc == ERR_NO_ERR ) {
            if( n >= 0 ) {
                cinfo = InfoHead;
                for( j = 0; j < n; ++j ) {
                    cinfo = cinfo->next;
                }
                BringUpFile( cinfo, true );
                switch( si.event ) {
                case VI_KEY( DUMMY ):
                case VI_KEY( F1 ):
                    break;
                case VI_KEY( F2 ):
                    rc = NextFile();
                    if( rc <= ERR_NO_ERR ) {
                        repeat = true;
                    }
                    break;
                case VI_KEY( F3 ):
                    rc = SaveAndExit( NULL );
                    if( rc <= ERR_NO_ERR ) {
                        repeat = true;
                    }
                    break;
                }
            }
        }

        filelistw_info.area.y2 = tmp;
        MemFreeList( fcnt, list );

    }

    /*
     * get rid of option stuff
     */
    CloseAWindow( wid );
    return( rc );

} /* EditFileFromList */