/[projet1]/public/pc/tools/osdk/main/makedisk/Floppy.cpp
Defence Force logotype

Diff of /public/pc/tools/osdk/main/makedisk/Floppy.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1044 by dbug, Tue Dec 17 21:24:32 2013 UTC revision 1045 by dbug, Fri Dec 20 17:42:53 2013 UTC
# Line 522  public: Line 522  public:
522  };  };
523    
524    
525  bool Floppy::WriteFile(const char *fileName,int loadAddress,bool removeHeaderIfPresent)  bool Floppy::WriteFile(const char *fileName,int loadAddress,bool removeHeaderIfPresent,const std::map<std::string,std::string>& metadata)
526  {  {
527    if (!m_Buffer)    if (!m_Buffer)
528    {    {
# Line 571  bool Floppy::WriteFile(const char *fileN Line 571  bool Floppy::WriteFile(const char *fileN
571    fileEntry.m_SectorCount=(fileSize+255)/256;    fileEntry.m_SectorCount=(fileSize+255)/256;
572    fileEntry.m_FilePath   =fileName;    fileEntry.m_FilePath   =fileName;
573    fileEntry.m_CompressionMode=e_CompressionNone;    fileEntry.m_CompressionMode=e_CompressionNone;
574      fileEntry.m_Metadata = metadata;
575    
576      for (auto metadataIt(metadata.begin());metadataIt!=metadata.end();++metadataIt)
577      {
578        m_MetadataCategories.insert(metadataIt->first);
579      }
580    
581    std::vector<unsigned char> compressedBuffer;    std::vector<unsigned char> compressedBuffer;
582    if (m_CompressionMode==e_CompressionFilepack)    if (m_CompressionMode==e_CompressionFilepack)
# Line 654  bool Floppy::SaveDescription(const char* Line 660  bool Floppy::SaveDescription(const char*
660    std::stringstream code_adress_low;    std::stringstream code_adress_low;
661    std::stringstream code_adress_high;    std::stringstream code_adress_high;
662    
663      std::map<std::string,std::stringstream>     metadata_content;
664    
665      std::set<std::string>                       metadata_entries;
666    
667      {
668        for (auto metadataIt(m_MetadataCategories.begin());metadataIt!=m_MetadataCategories.end();metadataIt++)
669        {
670          const std::string& metadataCategoryName(*metadataIt);
671          metadata_content[metadataCategoryName+"_Low"] << "_MetaData_" << metadataCategoryName << "_Low .byt ";
672          metadata_content[metadataCategoryName+"_High"] << "_MetaData_" << metadataCategoryName << "_High .byt ";
673        }
674      }
675    
676    
677    std::stringstream file_list_summary;    std::stringstream file_list_summary;
678    
679    int counter=0;    int counter=0;
# Line 676  bool Floppy::SaveDescription(const char* Line 696  bool Floppy::SaveDescription(const char*
696        code_track << ",";        code_track << ",";
697    
698        code_compressed << ",";        code_compressed << ",";
699    
700          {
701            for (auto metadataIt(metadata_content.begin());metadataIt!=metadata_content.end();metadataIt++)
702            {
703              metadataIt->second << ",";
704            }
705          }
706      }      }
707      code_adress_low  << "<" << fileEntry.m_LoadAddress;      code_adress_low  << "<" << fileEntry.m_LoadAddress;
708      code_adress_high << ">" << fileEntry.m_LoadAddress;      code_adress_high << ">" << fileEntry.m_LoadAddress;
# Line 688  bool Floppy::SaveDescription(const char* Line 715  bool Floppy::SaveDescription(const char*
715    
716      code_sector << fileEntry.m_StartSector;      code_sector << fileEntry.m_StartSector;
717    
718      file_list_summary << "// - Entry #" << counter << " '"<< fileEntry.m_FilePath << " ' loads at address " << fileEntry.m_LoadAddress;      file_list_summary << "// - Entry #" << counter << " '"<< fileEntry.m_FilePath << "'\n";
719        file_list_summary << "//   Loads at address " << fileEntry.m_LoadAddress;
720      if (fileEntry.m_StartTrack<m_TrackNumber)      if (fileEntry.m_StartTrack<m_TrackNumber)
721      {      {
722        // First side        // First side
# Line 714  bool Floppy::SaveDescription(const char* Line 742  bool Floppy::SaveDescription(const char*
742        file_list_summary << "(" << fileEntry.m_StoredFileSize << " compressed bytes: " << (fileEntry.m_StoredFileSize*100)/fileEntry.m_FinalFileSize << "% of " << fileEntry.m_FinalFileSize << " bytes).\n";        file_list_summary << "(" << fileEntry.m_StoredFileSize << " compressed bytes: " << (fileEntry.m_StoredFileSize*100)/fileEntry.m_FinalFileSize << "% of " << fileEntry.m_FinalFileSize << " bytes).\n";
743      }      }
744    
745    
746        {
747          file_list_summary << "//   Associated metadata: ";
748          for (auto metadataIt(m_MetadataCategories.begin());metadataIt!=m_MetadataCategories.end();metadataIt++)
749          {
750            const std::string& metadataCategoryName(*metadataIt);
751    
752            std::string metadataLabelEntry;
753            std::string metadataEntry;
754    
755            auto fileMetadataIt=fileEntry.m_Metadata.find(metadataCategoryName);
756            if (fileMetadataIt==fileEntry.m_Metadata.end())
757            {
758              // No entries for that one
759              metadataLabelEntry="metadata_none";
760              metadataEntry=metadataLabelEntry+" .byt \"\",0";
761            }
762            else
763            {
764              const std::string& key(fileMetadataIt->first);
765              const std::string& value(fileMetadataIt->second);
766              file_list_summary << key << "='" << value << "' ";
767    
768              std::string labelValue(StringMakeLabel(value));
769              metadataLabelEntry="metadata_"+key+"_"+labelValue;
770              metadataEntry=metadataLabelEntry+" .byt \""+value+"\",0";
771            }
772            metadata_entries.insert(metadataEntry);
773            metadata_content[metadataCategoryName+"_Low"] << "<" << metadataLabelEntry;
774            metadata_content[metadataCategoryName+"_High"] << ">" << metadataLabelEntry;
775          }
776        }
777    
778        if (!fileEntry.m_Metadata.empty())
779        {
780          for (auto metaIt(fileEntry.m_Metadata.begin());metaIt!=fileEntry.m_Metadata.end();++metaIt)
781          {
782          }
783          file_list_summary << "\n";
784        }
785    
786    
787      ++counter;      ++counter;
788    }    }
789    
# Line 743  bool Floppy::SaveDescription(const char* Line 813  bool Floppy::SaveDescription(const char*
813    layoutInfo << code_adress_high.str() << "\n";    layoutInfo << code_adress_high.str() << "\n";
814        
815    
816    layoutInfo << "#endif\n";    layoutInfo << "#endif // LOADER\n";
817    
818    layoutInfo << "#else\n";    layoutInfo << "#else\n";
819    layoutInfo << "//\n";    layoutInfo << "//\n";
# Line 754  bool Floppy::SaveDescription(const char* Line 824  bool Floppy::SaveDescription(const char*
824    layoutInfo << "\n";    layoutInfo << "\n";
825    layoutInfo << "//\n";    layoutInfo << "//\n";
826    layoutInfo << "// Summary for this floppy building session:\n";    layoutInfo << "// Summary for this floppy building session:\n";
827      layoutInfo << "//\n";
828    layoutInfo << "#define FLOPPY_SIDE_NUMBER " << m_SideNumber << "    // Number of sides\n";    layoutInfo << "#define FLOPPY_SIDE_NUMBER " << m_SideNumber << "    // Number of sides\n";
829    layoutInfo << "#define FLOPPY_TRACK_NUMBER " << m_TrackNumber << "    // Number of tracks\n";    layoutInfo << "#define FLOPPY_TRACK_NUMBER " << m_TrackNumber << "    // Number of tracks\n";
830    layoutInfo << "#define FLOPPY_SECTOR_PER_TRACK " << m_SectorNumber <<  "   // Number of sectors per track\n";    layoutInfo << "#define FLOPPY_SECTOR_PER_TRACK " << m_SectorNumber <<  "   // Number of sectors per track\n";
   layoutInfo << "//\n";  
831    
832      layoutInfo << "\n";
833      layoutInfo << "//\n";
834    layoutInfo << "// List of files written to the floppy\n";    layoutInfo << "// List of files written to the floppy\n";
835    layoutInfo << file_list_summary.str();    layoutInfo << file_list_summary.str();
836    layoutInfo << "//\n";    layoutInfo << "//\n";
# Line 780  bool Floppy::SaveDescription(const char* Line 852  bool Floppy::SaveDescription(const char*
852      }      }
853    }    }
854    
855      layoutInfo << "\n";
856      layoutInfo << "//\n";
857      layoutInfo << "// Metadata\n";
858      layoutInfo << "//\n";
859      layoutInfo << "#ifdef METADATA_STORAGE\n";
860    
861      {
862        for (auto metadataIt(metadata_entries.begin());metadataIt!=metadata_entries.end();metadataIt++)
863        {
864          layoutInfo << *metadataIt << "\n";
865        }
866      }
867      layoutInfo << "\n";
868    
869      {
870        for (auto metadataIt(metadata_content.begin());metadataIt!=metadata_content.end();metadataIt++)
871        {
872          layoutInfo << metadataIt->second.str() << "\n";
873        }
874      }
875      layoutInfo << "#endif // METADATA_STORAGE\n";
876      layoutInfo << "\n";
877    
878    if (!SaveFile(fileName,layoutInfo.str().c_str(),layoutInfo.str().length()))    if (!SaveFile(fileName,layoutInfo.str().c_str(),layoutInfo.str().length()))
879    {    {
880      ShowError("Can't save '%s'\n",fileName);      ShowError("Can't save '%s'\n",fileName);

Legend:
Removed from v.1044  
changed lines
  Added in v.1045

  ViewVC Help
Powered by ViewVC 1.1.26