2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/* Copyright (C) 2008 Jonathan Moore Liles */
|
|
|
|
/* */
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
/* option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
/* more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
2008-05-07 01:33:24 +02:00
|
|
|
/* Routings for opening/closing/creation of projects. All the actual
|
|
|
|
project state belongs to Timeline and other classes. */
|
2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2008-05-04 09:32:54 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
#include "Loggable.H"
|
2008-05-07 01:33:24 +02:00
|
|
|
#include "Project.H"
|
2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
#include "debug.h"
|
2008-05-07 01:33:24 +02:00
|
|
|
char Project::_name[256];
|
|
|
|
bool Project::_is_open = false;
|
2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
void
|
2008-05-07 01:33:24 +02:00
|
|
|
Project::set_name ( const char *name )
|
2008-05-04 09:10:15 +02:00
|
|
|
{
|
|
|
|
char *s = rindex( name, '/' );
|
|
|
|
|
2008-05-07 01:33:24 +02:00
|
|
|
strcpy( Project::_name, s ? s + 1 : name );
|
2008-05-04 09:10:15 +02:00
|
|
|
|
2008-05-07 01:33:24 +02:00
|
|
|
for ( s = Project::_name; *s; ++s )
|
2008-05-04 09:10:15 +02:00
|
|
|
if ( *s == '_' || *s == '-' )
|
|
|
|
*s = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
exists ( const char *name )
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
return 0 == stat( name, &st );
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
bool
|
2008-05-07 01:33:24 +02:00
|
|
|
Project::close ( void )
|
2008-05-04 09:10:15 +02:00
|
|
|
{
|
|
|
|
Loggable::close();
|
2008-05-06 06:33:41 +02:00
|
|
|
|
|
|
|
_is_open = false;
|
2008-05-04 09:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2008-05-07 01:33:24 +02:00
|
|
|
Project::open ( const char *name )
|
2008-05-04 09:10:15 +02:00
|
|
|
{
|
|
|
|
if ( chdir( name ) )
|
|
|
|
{
|
2008-05-07 01:33:24 +02:00
|
|
|
WARNING( "Cannot change to project dir \"%s\"", name );
|
2008-05-04 09:10:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! exists( "history" ) ||
|
|
|
|
! exists( "sources" ) )
|
|
|
|
// ! exists( "options" ) )
|
|
|
|
{
|
2008-05-07 01:33:24 +02:00
|
|
|
WARNING( "Not a Non-DAW project: \"%s\"", name );
|
2008-05-04 09:10:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! Loggable::open( "history" ) )
|
|
|
|
FATAL( "error opening journal" );
|
|
|
|
|
|
|
|
set_name( name );
|
2008-05-04 09:32:54 +02:00
|
|
|
|
2008-05-06 06:33:41 +02:00
|
|
|
_is_open = true;
|
|
|
|
|
2008-05-04 09:32:54 +02:00
|
|
|
return true;
|
2008-05-04 09:10:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2008-05-07 01:33:24 +02:00
|
|
|
Project::create ( const char *name, const char *template_name )
|
2008-05-04 09:10:15 +02:00
|
|
|
{
|
|
|
|
if ( exists( name ) )
|
|
|
|
{
|
2008-05-07 01:33:24 +02:00
|
|
|
WARNING( "Project already exists" );
|
2008-05-04 09:10:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( mkdir( name, 0777 ) )
|
|
|
|
{
|
2008-05-07 01:33:24 +02:00
|
|
|
WARNING( "Cannot create project directory" );
|
2008-05-04 09:10:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( chdir( name ) )
|
2008-05-07 01:33:24 +02:00
|
|
|
FATAL( "WTF? Cannot change to new project directory" );
|
2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
mkdir( "sources", 0777 );
|
|
|
|
|
2008-05-04 09:32:54 +02:00
|
|
|
creat( "history", 0666 );
|
2008-05-04 09:10:15 +02:00
|
|
|
|
|
|
|
/* TODO: copy template */
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
return open( name );
|
|
|
|
}
|