示例#1
0
func OpenProject(fileName string) (*Project, error) {
	var err error
	p := &Project{}
	p.projectFile, _ = filepath.Abs(fileName)
	p.projectDir = filepath.Dir(p.projectFile)
	p.cfg, err = loadConfig(fileName)
	for _, fn := range p.cfg.Files {
		fp := file.NewFile(fn)
		p.files = append(p.files, fp)
		fp.Open(p.projectDir)
	}

	return p, err
}
示例#2
0
func (p *Project) AddFile(relpath string) error {
	ppath := filepath.Join(p.projectDir, relpath)
	if _, err := os.Lstat(ppath); err != nil {
		return err
	}

	if p.GetFile(relpath) != nil {
		return nil
	}

	file := file.NewFile(relpath)
	p.files = append(p.files, file)
	return nil
}
示例#3
0
func (p *Project) NewFile(relpath string) error {
	ppath := filepath.Join(p.projectDir, relpath)
	f, err := os.Create(ppath)
	if err != nil {
		return err
	}

	f.Close()

	if p.GetFile(relpath) != nil {
		return nil
	}
	file := file.NewFile(relpath)
	p.files = append(p.files, file)
	return nil
}