source: golgotha/src/i4/loaders/mp3/enc_mirror.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.6 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "main/main.hh"
10#include "error/alert.hh"
11#include "error/error.hh"
12#include "file/file.hh"
13#include "string/str_checksum.hh"
14#include "memory/malloc.hh"
15#include "loaders/mp3_load.hh"
16#include "loaders/wav_load.hh"
17#include "status/status.hh"
18#include <stdio.h>
19
20i4_file_class *decomp_script=0;
21
22void copy_file(char *f1, char *f2)
23{
24  i4_file_class *out=i4_open(f2, I4_WRITE);
25  if (!out)
26  {
27    i4_warning("Could not open output file %s", f2);
28    return;
29  }
30
31  i4_file_class *in=i4_open(f1);
32  if (!in)
33  {
34    i4_warning("Could not open output file %s", f1);
35    return;
36  }
37
38  printf("copying %s -> %s\n", f1, f2);
39
40  char buf[4096];
41  int size=in->size();
42  while (size)
43  {
44    int t=in->read(buf, sizeof(buf));
45    out->write(buf, t);
46    size-=t;
47  }
48
49
50  delete in;
51  delete out;
52}
53
54void encode_mp3(char *s, char *d)
55{
56  char cmd[256];
57  printf("encoding %s -> %s\n", s,d);
58
59  if (decomp_script)
60    decomp_script->printf("(mp3_2_wav %s)\n",d);
61
62  sprintf(cmd, "mp3enc -esr 32 -if %s -of %s -qual 9 > NUL", s,d);
63  system(cmd);
64}
65
66void mcopy(const i4_const_str &s, const i4_const_str &d)
67{
68  i4_directory_struct df,sf;
69
70  if (i4_get_directory(s, sf, i4_T))
71  {
72    char src_path[256], dest_path[256];
73    i4_os_string(s, src_path, 256);
74    i4_os_string(d, dest_path, 256);
75
76    w8 *up_to_date=0;
77    if (sf.tfiles)
78    {
79      up_to_date=(w8 *)i4_malloc(sf.tfiles * sizeof(w8), "");
80      memset(up_to_date, 0, sf.tfiles * sizeof(w8));
81
82      i4_mkdir(d);
83      if (i4_get_directory(d, df, i4_T))
84      {
85        for (int i=0; i<sf.tfiles; i++)
86        {
87          for (int j=0; j<df.tfiles; j++)
88            if (*sf.files[i]==*df.files[j])
89              up_to_date[i]=1;
90        }
91      }
92    }
93
94
95    for (int i=0; i<sf.tfiles; i++)
96    {
97      if (!up_to_date[i])
98      {
99        i4_filename_struct fs;
100        i4_split_path(*sf.files[i], fs);
101        char src_fn[256], dst_fn[256];
102        sprintf(src_fn, "%s/%s.%s", src_path, fs.filename, fs.extension);
103
104        if (strcmp(fs.extension, "wav")==0 &&
105            strstr(fs.filename, "_lp")==0)
106        {
107          sprintf(dst_fn, "%s/%s.mp3", dest_path, fs.filename);
108          encode_mp3(src_fn, dst_fn);
109        }
110        else
111        {
112          sprintf(dst_fn, "%s/%s.%s", dest_path, fs.filename, fs.extension);
113          copy_file(src_fn, dst_fn);
114        }
115
116      }
117    }
118
119    if (sf.tfiles)
120      i4_free(up_to_date);
121
122
123    for (int j=0; j<sf.tdirs; j++)
124    {
125      char dir[256], new_src_path[256], new_dst_path[256];
126      i4_os_string(*sf.dirs[j], dir, 256);
127      if (!(strcmp(dir,".")==0 || strcmp(dir,"..")==0))
128      {
129        sprintf(new_src_path, "%s/%s", src_path, dir);
130        sprintf(new_dst_path, "%s/%s", dest_path, dir);
131
132        mcopy(new_src_path, new_dst_path);
133      }
134    }
135
136
137  }
138}
139
140void i4_main(w32 argc, i4_const_str *argv)
141{
142  i4_init();
143
144  if (argc>2)
145  {   
146    if (argc==3)
147      decomp_script=i4_open(argv[3],I4_WRITE);
148   
149    mcopy(argv[1], argv[2]);
150
151    if (decomp_script)
152      delete decomp_script;
153  }
154  else
155    printf("Ussage : source_directory directory_to_mirror_to\n");
156}
157
Note: See TracBrowser for help on using the repository browser.