/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018  - 2026 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ 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; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#+	astyle --style=banner --indent=tab Zippy.c.in
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	August 2, 2026

#define _GNU_SOURCE

#include "common/includes.h"
#include "common/structures.h"
#include "common/defines.h"
#include "common/common-fcn-headers.h"
#include "common/common-externs.h"

int	Cur_Dir(char *where) {

//----------------------------------------------------------------------
//	Establish the location for the code directory
//	The files 'program.lst' and 'sounders.config' should be here.
//	'program.lst' contains the references to the music files.
//----------------------------------------------------------------------

	char *home_env = NULL;
	char tmp[PGM_MAX];

	if (where != NULL) {
		home_env = where;
		}

	else {

		home_env = getenv("ZIPPY");

		if (home_env == NULL || file_stat(home_env) != S_IFDIR) 
			home_env = getenv("HOME");

		if (file_stat(home_env) != S_IFDIR || home_env == NULL) {
			printf("*** Unable to establish envirnment variable.\n");
			return EXIT_FAILURE;
			}
		}

	strcpy(Code_Home, home_env);

	if (Code_Home[strlen(Code_Home) - 1] == '/')
		Code_Home[strlen(Code_Home) - 1] = 0; // no trailing /

	printf("Code home directory: %s\n", Code_Home);

	strcpy(tmp, "mkdir -p \"");
	strcat(tmp, Code_Home);
	strcat(tmp, "/sgr-zippy/snapshots\"");
	system(tmp);
	printf("%s\n", tmp);

	strcpy(tmp, "mkdir -p \"");
	strcat(tmp, Code_Home);
	strcat(tmp, "/sgr-zippy/stills\"");
	system(tmp);
	printf("%s\n", tmp);

	strcpy(tmp, "mkdir -p \"");
	strcat(tmp, Code_Home);
	strcat(tmp, "/sgr-zippy/thumbnails\"");
	system(tmp);
	printf("%s\n", tmp);

	strcpy(Program_List, "\"");
	strcat(Program_List, Code_Home);
	strcat(Program_List,"/sgr-zippy/program.lst");	// file address of tmp.lst
	strcat(Program_List, "\"");
	printf("Program_List %s\n", Program_List);

	strcpy(Music_Home_Directory, Code_Home);
	printf("Music Home Directory: %s\n", Music_Home_Directory);

	gtk_label_set_text(GTK_LABEL(current_dir), Music_Home_Directory);

	return EXIT_SUCCESS;

	}
