// Stores files in the correct location
Stores files in the correct location
// Stores files in the correct location
func addFiles(files []ContentFile, contentType string) error {
	var contentPath string
	switch contentType {
	case "Track":
		contentPath = filepath.Join(ServerInstallPath, "content", "tracks")
	case "Car":
		contentPath = filepath.Join(ServerInstallPath, "content", "cars")
	case "Weather":
		contentPath = filepath.Join(ServerInstallPath, "content", "weather")
	}
	for _, file := range files {
		fileDecoded, err := base64.StdEncoding.DecodeString(base64HeaderRegex.ReplaceAllString(file.Data, ""))
		if err != nil {
			logrus.Errorf("could not decode "+contentType+" file data, err: %s", err)
			return err
		}
		parts := strings.Split(file.FilePath, "/")
		if parts[0] == "tracks" || parts[0] == "cars" || parts[0] == "weather" {
			parts = parts[1:]
			file.FilePath = ""
			for _, part := range parts {
				file.FilePath = filepath.Join(file.FilePath, part)
			}
		}
		path := filepath.Join(contentPath, file.FilePath)
		err = os.MkdirAll(filepath.Dir(path), 0755)
		if err != nil {
			logrus.Errorf("could not create "+contentType+" file directory, err: %s", err)
			return err
		}
		if contentType == "Car" {
			if _, name := filepath.Split(file.FilePath); name == "data.acd" {
				err := addTyresFromDataACD(file.FilePath, fileDecoded)
				if err != nil {
					logrus.Errorf("Could not create tyres for new car (%s), err: %s", file.FilePath, err)
				}
			} else if name == "tyres.ini" {
				err := addTyresFromTyresIni(file.FilePath, fileDecoded)
				if err != nil {
					logrus.Errorf("Could not create tyres for new car (%s), err: %s", file.FilePath, err)
				}
			}
		}
		err = ioutil.WriteFile(path, fileDecoded, 0644)
		if err != nil {
			logrus.Errorf("could not write file, err: %s", err)
			return err
		}
	}
	return nil
}
func addFiles ( files [ ] ContentFile , contentType string ) error { var contentPath string switch contentType { case " " : contentPath = filepath . Join ( ServerInstallPath , " " , " " ) case " " : contentPath = filepath . Join ( ServerInstallPath , " " , " " ) case " " : contentPath = filepath . Join ( ServerInstallPath , " " , " " ) } for _ , file := range files { fileDecoded , err := base64 . StdEncoding . DecodeString ( base64HeaderRegex . ReplaceAllString ( file . Data , " " ) ) if err != nil { logrus . Errorf ( " " + contentType + " " , err ) return err } parts := strings . Split ( file . FilePath , " " ) if parts [ 0 ] == " " || parts [ 0 ] == " " || parts [ 0 ] == " " { parts = parts [ 1 : ] file . FilePath = " " for _ , part := range parts { file . FilePath = filepath . Join ( file . FilePath , part ) } } path := filepath . Join ( contentPath , file . FilePath ) err = os . MkdirAll ( filepath . Dir ( path ) , 0755 ) if err != nil { logrus . Errorf ( " " + contentType + " " , err ) return err } if contentType == " " { if _ , name := filepath . Split ( file . FilePath ) ; name == " " { err := addTyresFromDataACD ( file . FilePath , fileDecoded ) if err != nil { logrus . Errorf ( " " , file . FilePath , err ) } } else if name == " " { err := addTyresFromTyresIni ( file . FilePath , fileDecoded ) if err != nil { logrus . Errorf ( " " , file . FilePath , err ) } } } err = ioutil . WriteFile ( path , fileDecoded , 0644 ) if err != nil { logrus . Errorf ( " " , err ) return err } } return nil }
Stores files in the correct location
Stores files in the correct location
// If user uploaded a "tracks" or "cars" folder containing multiple tracks // Makes any directories in the path that don't exist (there can be multiple) // it seems some cars don't pack their data into an ACD file, it's just in a folder called 'data' // so we can just grab tyres.ini from there.