1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// entry point
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <process.h>
#include <string>
#include <cstdlib>
#include <commdlg.h>
#include <fstream>
#include <sstream>
#include <cstring>
//#include <msclr\marshal_cppstd.h>
#include "Form1.h"
using namespace winForm1;
using namespace std;
using namespace System;
//using namespace msclr::interop;
#pragma comment(lib, "comdlg32.lib")

//function prototypes
void setTagName(string fileNameStr);
void setffmpeg(string fileNameStr);
void setmd5(string fileNameStr);
//std::string setValues_fromFfmpeg();

// Open file dialog box
string openfilename(char *filter = "All Files (*.*)\0*.*\0", HWND owner = NULL) {
          OPENFILENAME ofn;
          char fileName[MAX_PATH] = "";
          ZeroMemory(&ofn, sizeof(ofn));
          ofn.lStructSize = sizeof(OPENFILENAME);
          ofn.hwndOwner = owner;
          ofn.lpstrFilter  = filter;
          ofn.lpstrFile = fileName;
          ofn.nMaxFile = MAX_PATH;
          ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
          ofn.lpstrDefExt = "";
          string fileNameStr;
          if ( GetOpenFileName(&ofn) )
            fileNameStr = fileName;
          return fileNameStr;
}

// Our 'MAIN' which initialize openfilename and setName
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
          //data collection process
          string fileNameStr;
          fileNameStr = openfilename();
          cout << fileNameStr.c_str();
          cin.ignore();
          setTagName(fileNameStr.c_str());
          setffmpeg(fileNameStr.c_str());
          setmd5(fileNameStr.c_str());
          //setValues_fromFfmpeg();

          //set array variable to be passed to display windows
          std::string laArray[9];
          //get ffmpeg output file
          std::string filename("ffmpeg.txt");
          std::ifstream ifs(filename.c_str());
          const int MAXITEMS2 = 11;
          string myList2[11] = {"title", "comment", "rating", "artist", "album", "date", "track", "genre", "bitrate", "Duration"};
          std::stringstream oss;
          oss << ifs.rdbuf();
          if(!ifs && !ifs.eof())
            std::cerr << "Error reading file '" << filename << "'\n";
            std::string contents(oss.str());
            std::ofstream outFile;
            outFile.open("ffmpeg2.txt");
            //begin loop
            for (int i = 0; i < MAXITEMS2; i++)
              {
                size_t position = contents.find(myList2[i]);
                string myString;
                switch (i)
                {
                case 0:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 17, 31);
                    laArray[0]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 1:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[1]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 2:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[2]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 3:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[3]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 4:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[4]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 5:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[5]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 6:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[6]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 7:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[7]=myString;
                    outFile << myString << endl;
                  }
                  break;
                case 8:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    laArray[8]=myString;
                    outFile << myString << endl;
                  }
                  break;
                default:
                  if(position != std::string::npos)
                  {
                    myString=contents.substr(position + 0, 21);
                    outFile << myString << endl;
                  }

                }
            }
          return 0;


          // Enabling Windows XP visual effects before any controls are created
          Application::EnableVisualStyles();
          Application::SetCompatibleTextRenderingDefault(false); 

          // Create the main window and run it
          Application::Run(gcnew Form1(laArray, 11));
          return 0;
}

//function to dump media file idv3 tags using the DOS program tag
void setTagName(string fileNameStr){
        {
          const int MAXITEMS = 7;
          string myList[MAXITEMS] = {"TITLE", "ARTIST", "ALBUM", "YEAR", "TRACK", "GENRE", "COMMENT"};
          //loop to inject myList array data one at a time because output in file delivers only first field
          for (int i = 0; i < MAXITEMS; i++)
            {
              //each time we have to cycle through for each tag
              string command = "tag --nocheck --tostdoutn \""+ myList[i]+"\" \"";
              command+= fileNameStr; command += "\" >> \"output.txt\"";
              system(command.c_str());
              //here we open file to add a new line
              ofstream myfile;
              myfile.open ("output.txt",ios_base::app);
              myfile << ":" + myList[i] + "\n";

              myfile.close();

            }
        }
        
}
//function to dump media file idv3 tags and file info using the DOS program ffmpeg
void setffmpeg(string fileNameStr){
          string command = "ffmpeg -i ";
          command+= fileNameStr; command += "> ffmpeg.txt 2>>&1";
          system(command.c_str());
}
//function to dump md5 hash using md5deep
void setmd5(string fileNameStr){
          string command = "md5deep ";
          command+= fileNameStr; command += "> md5.txt 2>>&1";
          system(command.c_str());
};