Пример #1
0
int ALMRunConfig::SetcmdOrder(wxString& cmd,int order)
{
	if (order_cfg_time && order_cfg_time != wxFileModificationTime(order_cfg_file))
	{
		wxDELETE(order_conf);
		order_conf = new wxFileConfig(wxT("ALMRun"),wxEmptyString,order_cfg_file,wxEmptyString,wxCONFIG_USE_LOCAL_FILE); 
	}
	order = order_conf->ReadLong(cmd,0);
	order_conf->Write(cmd,++order);
	order_conf->Flush();
	order_cfg_time	= wxFileModificationTime(order_cfg_file);
	return order;
}
Пример #2
0
wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    // location has Unix path separators
    wxString right = GetRightLocation(location);
    wxFileName fn = wxFileSystem::URLToFileName(right);
    wxString fullpath = ms_root + fn.GetFullPath();

    if (!wxFileExists(fullpath))
        return (wxFSFile*) NULL;

    // we need to check whether we can really read from this file, otherwise
    // wxFSFile is not going to work
    wxFFileInputStream *is = new wxFFileInputStream(fullpath);
    if ( !is->Ok() )
    {
        delete is;
        return (wxFSFile*) NULL;
    }

    return new wxFSFile(is,
                        right,
                        GetMimeTypeFromExt(location),
                        GetAnchor(location)
#if wxUSE_DATETIME
                        ,wxDateTime(wxFileModificationTime(fullpath))
#endif // wxUSE_DATETIME
                        );
}
Пример #3
0
bool ArcApp::Create()
{
    // turn m_args into a list of files, i.e. expand wildcards, recurse
    // directories and remove duplicates
    NameMap files;
    MakeFileList(files);

    wxOutputStreamPtr out(MakeOutputStream());
    if (!out.get()) return false;

    wxArchiveOutputStreamPtr arc(m_factory->NewStream(*out));

    for (NameMap::iterator it = files.begin(); it != files.end(); ++it) {
        wxString name = it->second;
        wxDateTime dt(wxFileModificationTime(name));

        *m_info << "adding " << name.mb_str() << std::endl;

        if (wxDirExists(name)) {
            if (!arc->PutNextDirEntry(name, dt))
                return false;
        }
        else {
            wxFFileInputStream in(name);

            if (in.Ok()) {
                if (!arc->PutNextEntry(name, dt, in.GetSize()) ||
                        !arc->Write(in) || !in.Eof())
                    return false;
            }
        }
    }

    return arc->Close() && out->Close();
}
Пример #4
0
wxFSFile* wxLocalFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    // location has Unix path separators
    wxString right = GetRightLocation(location);
    wxFileName fn = wxFileSystem::URLToFileName(right);
    wxString fullpath = ms_root + fn.GetFullPath();

    if (!wxFileExists(fullpath))
        return NULL;

    // we need to check whether we can really read from this file, otherwise
    // wxFSFile is not going to work
#if wxUSE_FFILE
    wxFFileInputStream *is = new wxFFileInputStream(fullpath);
#elif wxUSE_FILE
    wxFileInputStream *is = new wxFileInputStream(fullpath);
#else
#error One of wxUSE_FILE or wxUSE_FFILE must be set to 1 for wxFSHandler to work
#endif
    if ( !is->IsOk() )
    {
        delete is;
        return NULL;
    }

    return new wxFSFile(is,
                        location,
                        wxEmptyString,
                        GetAnchor(location)
#if wxUSE_DATETIME
                        ,wxDateTime(wxFileModificationTime(fullpath))
#endif // wxUSE_DATETIME
                        );
}
Пример #5
0
wxFSFile* wxChmFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs),
                                   const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);

    wxInputStream *s;

    int index;

    if ( GetProtocol(left) != _T("file") )
    {
        wxLogError(_("CHM handler currently supports only local files!"));
        return NULL;
    }

    // Work around javascript
    wxString tmp = wxString(right);
    if ( tmp.MakeLower().Contains(_T("javascipt")) && tmp.Contains(_T("\'")) )
    {
        right = right.AfterFirst(_T('\'')).BeforeLast(_T('\''));
    }

    // now work on the right location
    if (right.Contains(_T("..")))
    {
        wxFileName abs(right);
        abs.MakeAbsolute(_T("/"));
        right = abs.GetFullPath();
    }

    // a workaround for absolute links to root
    if ( (index=right.Index(_T("//"))) != wxNOT_FOUND )
    {
        right=wxString(right.Mid(index+1));
        wxLogWarning(_("Link contained '//', converted to absolute link."));
    }

    wxFileName leftFilename = wxFileSystem::URLToFileName(left);

    // Open a stream to read the content of the chm-file
    s = new wxChmInputStream(leftFilename.GetFullPath(), right, true);

    wxString mime = GetMimeTypeFromExt(location);

    if ( s )
    {
        return new wxFSFile(s,
                            left + _T("#chm:") + right,
                            mime,
                            GetAnchor(location),
                            wxDateTime(wxFileModificationTime(left)));
    }

    delete s;
    return NULL;
}
Пример #6
0
/* DirArchive::loadEntryData
 * Loads an entry's data from the saved copy of the archive if any
 *******************************************************************/
bool DirArchive::loadEntryData(ArchiveEntry* entry)
{
	if (entry->importFile(entry->exProp("filePath").getStringValue()))
	{
		file_modification_times[entry] = wxFileModificationTime(entry->exProp("filePath").getStringValue());
		return true;
	}

	return false;
}
Пример #7
0
	bool exportEntry()
	{
		wxFileName fn(appPath(entry->getName(), DIR_TEMP));
		fn.SetExt("mid");

		// Convert to WAV data
		MemChunk convdata;

		// Doom Sound
		if (entry->getType()->getFormat() == "snd_doom" ||
			entry->getType()->getFormat() == "snd_doom_mac")
			Conversions::doomSndToWav(entry->getMCData(), convdata);

		// Doom PC Speaker Sound
		else if (entry->getType()->getFormat() == "snd_speaker")
			Conversions::spkSndToWav(entry->getMCData(), convdata);

		// AudioT PC Speaker Sound
		else if (entry->getType()->getFormat() == "snd_audiot")
			Conversions::spkSndToWav(entry->getMCData(), convdata, true);

		// Wolfenstein 3D Sound
		else if (entry->getType()->getFormat() == "snd_wolf")
			Conversions::wolfSndToWav(entry->getMCData(), convdata);

		// Creative Voice File
		else if (entry->getType()->getFormat() == "snd_voc")
			Conversions::vocToWav(entry->getMCData(), convdata);

		// Jaguar Doom Sound
		else if (entry->getType()->getFormat() == "snd_jaguar")
			Conversions::jagSndToWav(entry->getMCData(), convdata);

		// Blood Sound
		else if (entry->getType()->getFormat() == "snd_bloodsfx")
			Conversions::bloodToWav(entry, convdata);

		else
		{
			Global::error = S_FMT("Type %s can not be converted to WAV", CHR(entry->getType()->getName()));
			return false;
		}

		// Export file and start monitoring if successful
		filename = fn.GetFullPath();
		if (convdata.exportFile(filename))
		{
			file_modified = wxFileModificationTime(filename);
			Start(1000);
			return true;
		}

		return false;
	}
Пример #8
0
bool ALMRunConfig::SaveCfg()
{
	if (!conf)
		return false;
	conf->Flush();
	if (cfg_time)
	{
		cfg_time = wxFileModificationTime(cfg_file);
		cfg_changed = false;
	}
	return true;
}
Пример #9
0
wxFSFile* wxZipFSHandler::OpenFile(wxFileSystem& WXUNUSED(fs), const wxString& location)
{
    wxString right = GetRightLocation(location);
    wxString left = GetLeftLocation(location);
    wxZipInputStream *s;

    if (right.Contains(wxT("./")))
    {
        if (right.GetChar(0) != wxT('/')) right = wxT('/') + right;
        wxFileName rightPart(right, wxPATH_UNIX);
        rightPart.Normalize(wxPATH_NORM_DOTS, wxT("/"), wxPATH_UNIX);
        right = rightPart.GetFullPath(wxPATH_UNIX);
    }

    if (right.GetChar(0) == wxT('/')) right = right.Mid(1);

    // a new wxFileSystem object is needed here to avoid infinite recursion
    wxFSFile *leftFile = wxFileSystem().OpenFile(left);
    if (!leftFile)
       return NULL;

    s = new wxZipFSInputStream(leftFile);
    if (s && s->IsOk())
    {
       bool found = false;
       while (!found)
       {
           wxZipEntry *ent = s->GetNextEntry();
           if (!ent)
               break;
           if (ent->GetInternalName() == right)
               found = true;
           delete ent;
       }
       if (found)
           return new wxFSFile(s,
                            left + wxT("#zip:") + right,
                            GetMimeTypeFromExt(location),
                            GetAnchor(location)
#if wxUSE_DATETIME
                            , wxDateTime(wxFileModificationTime(left))
#endif // wxUSE_DATETIME
                            );
    }

    delete s;
    return NULL;
}
Пример #10
0
	virtual bool exportEntry()
	{
		// Determine export filename/path
		wxFileName fn(appPath(entry->getName(), DIR_TEMP));
		fn.SetExt(entry->getType()->getExtension());

		// Export entry and start monitoring
		bool ok = entry->exportFile(fn.GetFullPath());
		if (ok)
		{
			filename = fn.GetFullPath();
			file_modified = wxFileModificationTime(filename);
			Start(1000);
		}
		else
			Global::error = "Failed to export entry";

		return ok;
	}
Пример #11
0
	bool exportEntry()
	{
		wxFileName fn(appPath(entry->getName(), DIR_TEMP));

		fn.SetExt("png");

		// Create image from entry
		SImage image;
		if (!Misc::loadImageFromEntry(&image, entry))
		{
			Global::error = "Could not read graphic";
			return false;
		}

		// Set export info
		gfx_format = image.getFormat()->getId();
		offsets = image.offset();
		palette.copyPalette(theMainWindow->getPaletteChooser()->getSelectedPalette(entry));

		// Write png data
		MemChunk png;
		SIFormat* fmt_png = SIFormat::getFormat("png");
		if (!fmt_png->saveImage(image, png, &palette))
		{
			Global::error = "Error converting to png";
			return false;
		}

		// Export file and start monitoring if successful
		filename = fn.GetFullPath();
		if (png.exportFile(filename))
		{
			file_modified = wxFileModificationTime(filename);
			Start(1000);
			return true;
		}

		return false;
	}
Пример #12
0
	bool exportEntry()
	{
		wxFileName fn(appPath(entry->getName(), DIR_TEMP));
		fn.SetExt("mid");

		// Convert to MIDI data
		MemChunk convdata;

		// MUS
		if (entry->getType()->getFormat() == "midi_mus")
			Conversions::musToMidi(entry->getMCData(), convdata);

		// HMI/HMP/XMI
		else if (entry->getType()->getFormat() == "midi_xmi" || 
			entry->getType()->getFormat() == "midi_hmi" || entry->getType()->getFormat() == "midi_hmp")
			Conversions::zmusToMidi(entry->getMCData(), convdata, 0);

		// GMID
		else if (entry->getType()->getFormat() == "midi_gmid")
			Conversions::gmidToMidi(entry->getMCData(), convdata);

		else
		{
			Global::error = S_FMT("Type %s can not be converted to MIDI", CHR(entry->getType()->getName()));
			return false;
		}

		// Export file and start monitoring if successful
		filename = fn.GetFullPath();
		if (convdata.exportFile(filename))
		{
			file_modified = wxFileModificationTime(filename);
			Start(1000);
			return true;
		}

		return false;
	}
Пример #13
0
bool ArcApp::Add()
{
    // turn m_args into a list of files, i.e. expand wildcards, recurse
    // directories and remove duplicates
    NameMap files;
    MakeFileList(files);

    wxInputStreamPtr in(MakeInputStream());
    if (!in.get()) return false;
    wxOutputStreamPtr out(MakeOutputStream());
    if (!out.get()) return false;

    wxArchiveInputStreamPtr  arc(m_factory->NewStream(*in));
    wxArchiveOutputStreamPtr outarc(m_factory->NewStream(*out));
    wxArchiveEntryPtr        entry(arc->GetNextEntry());

    outarc->CopyArchiveMetaData(*arc);

    for (;;) {
        bool keep;
        NameMap::iterator it;

        if (!entry.get()) {
            if (files.empty())
                break;
            it = files.begin();
            keep = false;
        } else {
            it = files.find(entry->GetInternalName());
            keep = true;
        }

        if (it != files.end()) {
            wxString name = it->second;
            files.erase(it);

            if (wxDirExists(name)) {
                *m_info << "adding " << name.mb_str() << std::endl;
                wxDateTime dt(wxFileModificationTime(name));
                if (!outarc->PutNextDirEntry(name, dt))
                    return false;
                keep = false;
            } else {
                wxFFileInputStream file(name);

                if (file.Ok()) {
                    *m_info << "adding " << name.mb_str() << std::endl;
                    wxDateTime dt(wxFileModificationTime(name));
                    if (!outarc->PutNextEntry(name, dt, file.GetSize()) ||
                            !outarc->Write(file) || !file.Eof())
                        return false;
                    keep = false;
                }
            }
        }

        if (keep)
            if (!outarc->CopyEntry(entry.release(), *arc))
                return false;

        if (entry.get() || keep)
            entry.reset(arc->GetNextEntry());
    }

    in.reset();
    return arc->Eof() && outarc->Close() && out->Close();
}
Пример #14
0
bool ALMRunConfig::Changed()
{
	if (cfg_changed)
		this->SaveCfg();
	return (cfg_time  && cfg_time != wxFileModificationTime(cfg_file));
}
Пример #15
0
ALMRunConfig::ALMRunConfig()
{
	//初始化默认参数
	config[OrderByPre] = false;
	config[NumberKey] = false;
	config[ExecuteIfOnlyOne] = false;
	config[ShowTip] = false;
	config[AutoRun] = false;
	config[AddToSendTo] = false;
	config[PlayPopupNotify] = false;
	config[SpaceKey] = false;
	config[DoubleToggleFunc] = false;
	config[DoubleClick] = false;
	config[DuplicateCMD] = false;
	cfg_changed = false;
	FavoriteList = NULL;
	order_conf = NULL;
	conf = NULL;
	order_cfg_time = 0;
	cfg_time = 0;

	if (wxGetEnv(wxT("ALMRUN_HOME"),&Home))
	{	
		cfg_file = Home + wxT("config/ALMRun.ini");
		order_cfg_file = Home + wxT("config/Order.ini");
		if (wxFileExists(order_cfg_file))
			order_cfg_time =  wxFileModificationTime(order_cfg_file);
		order_conf = new wxFileConfig(wxT("ALMRun"),wxEmptyString,order_cfg_file,wxEmptyString,wxCONFIG_USE_LOCAL_FILE);
		order_conf->SetExpandEnvVars(false);
		if (!wxFileExists(cfg_file))
			MoveFile(Home + wxGetApp().GetAppName().Append(".ini"),cfg_file);
	}
	if (wxFileExists(cfg_file) == false)
		cfg_file = wxEmptyString;
	else
		cfg_time = wxFileModificationTime(cfg_file);

	//lastId = 0;
	conf = new wxFileConfig(wxT("ALMRun"),wxEmptyString,cfg_file,wxEmptyString,7);
	gui_config[ListFont] = conf->Read("/GUI/ListFont");
	MerryListBoxPanel* listBoxPanel = ::wxGetApp().GetFrame().GetListBoxPanel();
	listBoxPanel->SetFont(gui_config[ListFont]);
	conf->SetPath("/Config");
	conf->SetRecordDefaults(false);
	config_u[CONFIG_VER] = conf->ReadLong("Version",-1);
	if (config_u[CONFIG_VER] == -1)//配置文件未标注版本
		cfg_changed = conf->Write("Version",(config_u[CONFIG_VER] = CONFIG_VERSION));
	config_u[ParamHistoryLimit] = conf->ReadLong("ParamHistoryLimit",ParamHistoryLimit_default);
	CompareMode = conf->ReadLong("CompareMode",0);
	this->set("Explorer",conf->Read("Explorer"));
	this->set("Root",conf->Read("Root"));

	//从配置文件中读取参数,如果不存在则使用默认值
	for(int i=0;i<CONFIG_BOOL_MAX;++i)
		config[i] = conf->ReadBool(config_str[i],config[i]);

	this->set("ShowTrayIcon",config[ShowTrayIcon]);
	this->set("StayOnTop",config[StayOnTop]);
	g_config = this;

	//程序显隐热键配置
	HotKey = conf->Read("HotKey","A-R");
	if (!g_hotkey->RegisterHotkey(g_commands->AddCommand(wxEmptyString,wxEmptyString,"toggleMerry",-1,HotKey,0)))
	{
		this->set("ShowTrayIcon",true);
		wxMessageBox(wxString::Format("热键 %s 注册失败!",HotKey),"错误提示",0x00000100);
	}
	//重载配置热键配置
	HotKeyReLoad = conf->Read("HotKeyReLoad");
	if (!HotKeyReLoad.empty())
		g_hotkey->RegisterHotkey(g_commands->AddCommand(wxEmptyString,wxEmptyString,"ReConfig",-1,HotKeyReLoad,0));
	//上一个运行的命令热键配置
	LastItemHotKey = conf->Read("LastItemHotKey");
	if (!LastItemHotKey.empty())
		g_hotkey->RegisterHotkey(g_commands->AddCommand(wxEmptyString,wxEmptyString,"LastCmd",-2,LastItemHotKey,0));

	this->OldToNew();

	ConfigCommand();
	if (config[RememberFavouratMatch])
		FavoriteList = new wxFileConfig(wxT("ALMRun"),wxEmptyString,Home +  FAVORITELIST_FILE ,wxEmptyString,wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH | wxCONFIG_USE_NO_ESCAPE_CHARACTERS);

#ifndef _DEBUG
	conf->SetPath("/Config");

	#ifdef __WXMSW__
	wxString Sendto = wxStandardPaths::MSWGetShellDir(0x0009) + "/ALMRun.lnk";//CSIDL_SENDTO                    0x0009        // <user name>\SendTo
	wxString Startup = wxStandardPaths::MSWGetShellDir(0x0007) + "/ALMRun.lnk";//CSIDL_STARTUP
	bool InSendTo = ::wxFileExists(Sendto);
	bool InStartup = ::wxFileExists(Startup);
	if (config[AddToSendTo])
	{
		if (InSendTo == false)
		{
			if (!CreateFileShortcut(::wxGetApp().argv[0],Sendto.c_str(),Home,0,_T("ALMRun 快速启动工具")))
				wxMessageBox("添加到<发送到>菜单失败!");
		}
		
	}
	else if (InSendTo)
	{
		wxRemoveFile(Sendto);
	}

	if (config[AutoRun])
	{
		if (InStartup == false)
		{
			if (!CreateFileShortcut(::wxGetApp().argv[0],Startup.c_str(),Home,0,_T("ALMRun 快速启动工具")))
				wxMessageBox("添加自动启动到<开始/启动>失败!");
		}

	}
	else if (InStartup)
	{
		wxRemoveFile(Startup);
	}
	#endif
#endif
}
Пример #16
0
/* DirArchive::open
 * Reads files from the directory [filename] into the archive
 * Returns true if successful, false otherwise
 *******************************************************************/
bool DirArchive::open(string filename)
{
	theSplashWindow->setProgressMessage("Reading directory structure");
	theSplashWindow->setProgress(0);
	//wxArrayString files;
	//wxDir::GetAllFiles(filename, &files, wxEmptyString, wxDIR_FILES|wxDIR_DIRS);
	vector<string> files, dirs;
	DirArchiveTraverser traverser(files, dirs);
	wxDir dir(filename);
	dir.Traverse(traverser, "", wxDIR_FILES | wxDIR_DIRS);

	theSplashWindow->setProgressMessage("Reading files");
	for (unsigned a = 0; a < files.size(); a++)
	{
		theSplashWindow->setProgress((float)a / (float)files.size());

		// Cut off directory to get entry name + relative path
		string name = files[a];
		name.Remove(0, filename.Length());
		if (name.StartsWith(separator))
			name.Remove(0, 1);

		//LOG_MESSAGE(3, fn.GetPath(true, wxPATH_UNIX));

		// Create entry
		wxFileName fn(name);
		ArchiveEntry* new_entry = new ArchiveEntry(fn.GetFullName());

		// Setup entry info
		new_entry->setLoaded(false);
		new_entry->exProp("filePath") = files[a];

		// Add entry and directory to directory tree
		ArchiveTreeNode* ndir = createDir(fn.GetPath(true, wxPATH_UNIX));
		ndir->addEntry(new_entry);
		ndir->getDirEntry()->exProp("filePath") = filename + fn.GetPath(true, wxPATH_UNIX);

		// Read entry data
		new_entry->importFile(files[a]);
		new_entry->setLoaded(true);

		time_t modtime = wxFileModificationTime(files[a]);
		file_modification_times[new_entry] = modtime;

		// Detect entry type
		EntryType::detectEntryType(new_entry);

		// Unload data if needed
		if (!archive_load_data)
			new_entry->unloadData();
	}

	// Add empty directories
	for (unsigned a = 0; a < dirs.size(); a++)
	{
		string name = dirs[a];
		name.Remove(0, filename.Length());
		if (name.StartsWith(separator))
			name.Remove(0, 1);
		name.Replace("\\", "/");
		ArchiveTreeNode* ndir = createDir(name);
		ndir->getDirEntry()->exProp("filePath") = dirs[a];
	}

	// Set all entries/directories to unmodified
	vector<ArchiveEntry*> entry_list;
	getEntryTreeAsList(entry_list);
	for (size_t a = 0; a < entry_list.size(); a++)
		entry_list[a]->setState(0);

	// Enable announcements
	setMuted(false);

	// Setup variables
	this->filename = filename;
	setModified(false);
	on_disk = true;

	theSplashWindow->setProgressMessage("");

	return true;
}
Пример #17
0
/* DirArchive::updateChangedEntries
 * Updates entries/directories based on [changes] list
 *******************************************************************/
void DirArchive::updateChangedEntries(vector<dir_entry_change_t>& changes)
{
	bool was_modified = isModified();

	for (unsigned a = 0; a < changes.size(); a++)
	{
		ignored_file_changes.erase(changes[a].file_path);

		// Modified Entries
		if (changes[a].action == dir_entry_change_t::UPDATED)
		{
			ArchiveEntry* entry = entryAtPath(changes[a].entry_path);
			entry->importFile(changes[a].file_path);
			EntryType::detectEntryType(entry);
			file_modification_times[entry] = wxFileModificationTime(changes[a].file_path);
		}

		// Deleted Entries
		else if (changes[a].action == dir_entry_change_t::DELETED_FILE)
			removeEntry(entryAtPath(changes[a].entry_path));

		// Deleted Directories
		else if (changes[a].action == dir_entry_change_t::DELETED_DIR)
			removeDir(changes[a].entry_path);

		// New Directory
		else if (changes[a].action == dir_entry_change_t::ADDED_DIR)
		{
			string name = changes[a].file_path;
			name.Remove(0, filename.Length());
			if (name.StartsWith(separator))
				name.Remove(0, 1);
			name.Replace("\\", "/");

			ArchiveTreeNode* ndir = createDir(name);
			ndir->getDirEntry()->setState(0);
			ndir->getDirEntry()->exProp("filePath") = changes[a].file_path;
		}

		// New Entry
		else if (changes[a].action == dir_entry_change_t::ADDED_FILE)
		{
			string name = changes[a].file_path;
			name.Remove(0, filename.Length());
			if (name.StartsWith(separator))
				name.Remove(0, 1);
			name.Replace("\\", "/");

			// Create entry
			wxFileName fn(name);
			ArchiveEntry* new_entry = new ArchiveEntry(fn.GetFullName());

			// Setup entry info
			new_entry->setLoaded(false);
			new_entry->exProp("filePath") = changes[a].file_path;

			// Add entry and directory to directory tree
			ArchiveTreeNode* ndir = createDir(fn.GetPath(true, wxPATH_UNIX));
			ndir->addEntry(new_entry);

			// Read entry data
			new_entry->importFile(changes[a].file_path);
			new_entry->setLoaded(true);

			time_t modtime = wxFileModificationTime(changes[a].file_path);
			file_modification_times[new_entry] = modtime;

			// Detect entry type
			EntryType::detectEntryType(new_entry);

			// Unload data if needed
			if (!archive_load_data)
				new_entry->unloadData();

			// Set entry not modified
			new_entry->setState(0);
		}
	}

	// Preserve old modified state
	setModified(was_modified);
}
Пример #18
0
static void AddCatalogToList(wxListCtrl *list, int i, int id, const wxString& file)
{
    wxConfigBase *cfg = wxConfig::Get();
    int all = 0, fuzzy = 0, untranslated = 0, badtokens = 0;
    wxString lastmodified;
    time_t modtime;
    wxString key;
    wxString file2(file);
    file2.Replace("/", "_");
    file2.Replace("\\", "_");
    // FIXME: move cache to cache file and out of *config* file!
    key.Printf("Manager/project_%i/FilesCache/%s/", id, file2.c_str());

    modtime = cfg->Read(key + "timestamp", (long)0);

    if (modtime == wxFileModificationTime(file))
    {
        all = (int)cfg->Read(key + "all", (long)0);
        fuzzy = (int)cfg->Read(key + "fuzzy", (long)0);
        badtokens = (int)cfg->Read(key + "badtokens", (long)0);
        untranslated = (int)cfg->Read(key + "untranslated", (long)0);
        lastmodified = cfg->Read(key + "lastmodified", "?");
    }
    else
    {
        // suppress error messages, we don't mind if the catalog is corrupted
        // FIXME: *do* indicate error somehow
        wxLogNull nullLog;

        // FIXME: don't re-load the catalog if it's already loaded in the
        //        editor, reuse loaded instance
        Catalog cat(file);
        cat.GetStatistics(&all, &fuzzy, &badtokens, &untranslated, NULL);
        modtime = wxFileModificationTime(file);
        lastmodified = cat.Header().RevisionDate;
        cfg->Write(key + "timestamp", (long)modtime);
        cfg->Write(key + "all", (long)all);
        cfg->Write(key + "fuzzy", (long)fuzzy);
        cfg->Write(key + "badtokens", (long)badtokens);
        cfg->Write(key + "untranslated", (long)untranslated);
        cfg->Write(key + "lastmodified", lastmodified);
    }

    int icon;
    if (fuzzy+untranslated+badtokens == 0) icon = 2;
    else if ((double)all / (fuzzy+untranslated+badtokens) <= 3) icon = 0;
    else icon = 1;

    wxString tmp;
    // FIXME: don't put full filename there, remove common prefix (of all
    //        directories in project's settings)
    list->InsertItem(i, file, icon);
    tmp.Printf("%i", all);
    list->SetItem(i, 1, tmp);
    tmp.Printf("%i", untranslated);
    list->SetItem(i, 2, tmp);
    tmp.Printf("%i", fuzzy);
    list->SetItem(i, 3, tmp);
    tmp.Printf("%i", badtokens);
    list->SetItem(i, 4, tmp);
    list->SetItem(i, 5, lastmodified);
}
Пример #19
0
void wxFileData::ReadData()
{
    if (IsDrive())
    {
        m_size = 0;
        return;
    }

#if defined(__DOS__) || (defined(__WINDOWS__) && !defined(__WXWINCE__)) || defined(__OS2__)
    // c:\.. is a drive don't stat it
    if ((m_fileName == wxT("..")) && (m_filePath.length() <= 5))
    {
        m_type = is_drive;
        m_size = 0;
        return;
    }
#endif // __DOS__ || __WINDOWS__

#ifdef __WXWINCE__

    // WinCE

    DWORD fileAttribs = GetFileAttributes(m_filePath.fn_str());
    m_type |= (fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0 ? is_dir : 0;

    wxString p, f, ext;
    wxSplitPath(m_filePath, & p, & f, & ext);
    if (wxStricmp(ext, wxT("exe")) == 0)
        m_type |= is_exe;

    // Find out size
    m_size = 0;
    HANDLE fileHandle = CreateFile(m_filePath.fn_str(),
                                   GENERIC_READ,
                                   FILE_SHARE_READ,
                                   NULL,
                                   OPEN_EXISTING,
                                   FILE_ATTRIBUTE_NORMAL,
                                   NULL);

    if (fileHandle != INVALID_HANDLE_VALUE)
    {
        m_size = GetFileSize(fileHandle, 0);
        CloseHandle(fileHandle);
    }

    m_dateTime = wxFileModificationTime(m_filePath);

#else

    // OTHER PLATFORMS

    wxStructStat buff;

#if defined(__UNIX__) && (!defined( __OS2__ ) && !defined(__VMS))
    lstat( m_filePath.fn_str(), &buff );
    m_type |= S_ISLNK( buff.st_mode ) != 0 ? is_link : 0;
#else // no lstat()
    // only translate to file charset if we don't go by our
    // wxStat implementation
#ifndef wxNEED_WX_UNISTD_H
    wxStat( m_filePath.fn_str() , &buff );
#else
    wxStat( m_filePath, &buff );
#endif
#endif

    m_type |= (buff.st_mode & S_IFDIR) != 0 ? is_dir : 0;
    m_type |= (buff.st_mode & wxS_IXUSR) != 0 ? is_exe : 0;
    m_size = (long)buff.st_size;

    m_dateTime = buff.st_mtime;
#endif
    // __WXWINCE__

#if defined(__UNIX__)
    m_permissions.Printf(_T("%c%c%c%c%c%c%c%c%c"),
                         buff.st_mode & wxS_IRUSR ? _T('r') : _T('-'),
                         buff.st_mode & wxS_IWUSR ? _T('w') : _T('-'),
                         buff.st_mode & wxS_IXUSR ? _T('x') : _T('-'),
                         buff.st_mode & wxS_IRGRP ? _T('r') : _T('-'),
                         buff.st_mode & wxS_IWGRP ? _T('w') : _T('-'),
                         buff.st_mode & wxS_IXGRP ? _T('x') : _T('-'),
                         buff.st_mode & wxS_IROTH ? _T('r') : _T('-'),
                         buff.st_mode & wxS_IWOTH ? _T('w') : _T('-'),
                         buff.st_mode & wxS_IXOTH ? _T('x') : _T('-'));
#elif defined(__WIN32__)
    DWORD attribs = GetFileAttributes(m_filePath.fn_str());
    if (attribs != (DWORD)-1)
    {
        m_permissions.Printf(_T("%c%c%c%c"),
                             attribs & FILE_ATTRIBUTE_ARCHIVE  ? _T('A') : _T(' '),
                             attribs & FILE_ATTRIBUTE_READONLY ? _T('R') : _T(' '),
                             attribs & FILE_ATTRIBUTE_HIDDEN   ? _T('H') : _T(' '),
                             attribs & FILE_ATTRIBUTE_SYSTEM   ? _T('S') : _T(' '));
    }
#endif

    // try to get a better icon
    if (m_image == wxFileIconsTable::file)
    {
        if (m_fileName.Find(wxT('.'), true) != wxNOT_FOUND)
        {
            m_image = wxTheFileIconsTable->GetIconID( m_fileName.AfterLast(wxT('.')));
        } else if (IsExe())
        {
            m_image = wxFileIconsTable::executable;
        }
    }
}
Пример #20
0
/* DirArchive::save
 * Saves any changes to the directory to the file system
 *******************************************************************/
bool DirArchive::save(string filename)
{
	// Get flat entry list
	vector<ArchiveEntry*> entries;
	getEntryTreeAsList(entries);

	// Get entry path list
	vector<string> entry_paths;
	for (unsigned a = 0; a < entries.size(); a++)
	{
		entry_paths.push_back(this->filename + entries[a]->getPath(true));
		if (separator != "/") entry_paths.back().Replace("/", separator);
	}

	// Get current directory structure
	long time = theApp->runTimer();
	vector<string> files, dirs;
	DirArchiveTraverser traverser(files, dirs);
	wxDir dir(this->filename);
	dir.Traverse(traverser, "", wxDIR_FILES|wxDIR_DIRS);
	//wxDir::GetAllFiles(this->filename, &files, wxEmptyString, wxDIR_FILES|wxDIR_DIRS);
	LOG_MESSAGE(2, "GetAllFiles took %lums", theApp->runTimer() - time);

	// Check for any files to remove
	time = theApp->runTimer();
	for (unsigned a = 0; a < removed_files.size(); a++)
	{
		if (wxFileExists(removed_files[a]))
		{
			LOG_MESSAGE(2, "Removing file %s", removed_files[a]);
			wxRemoveFile(removed_files[a]);
		}
	}

	// Check for any directories to remove
	for (int a = dirs.size() - 1; a >= 0; a--)
	{
		// Check if dir path matches an existing dir
		bool found = false;
		for (unsigned e = 0; e < entry_paths.size(); e++)
		{
			if (dirs[a] == entry_paths[e])
			{
				found = true;
				break;
			}
		}

		// Dir on disk isn't part of the archive in memory
		// (Note that this will fail if there are any untracked files in the
		// directory)
		if (!found && wxRmdir(dirs[a]))
			LOG_MESSAGE(2, "Removing directory %s", dirs[a]);
	}
	LOG_MESSAGE(2, "Remove check took %lums", theApp->runTimer() - time);

	// Go through entries
	vector<string> files_written;
	for (unsigned a = 0; a < entries.size(); a++)
	{
		// Check for folder
		string path = entry_paths[a];
		if (entries[a]->getType() == EntryType::folderType())
		{
			// Create if needed
			if (!wxDirExists(path))
				wxMkdir(path);

			// Set unmodified
			entries[a]->exProp("filePath") = path;
			entries[a]->setState(0);

			continue;
		}

		// Check if entry needs to be (re)written
		if (entries[a]->getState() == 0 && path == entries[a]->exProp("filePath").getStringValue())
			continue;

		// Write entry to file
		if (!entries[a]->exportFile(path))
		{
			LOG_MESSAGE(1, "Unable to save entry %s: %s", entries[a]->getName(), Global::error);
		}
		else
			files_written.push_back(path);

		// Set unmodified
		entries[a]->setState(0);
		entries[a]->exProp("filePath") = path;
		file_modification_times[entries[a]] = wxFileModificationTime(path);
	}

	removed_files.clear();
	setModified(false);

	return true;
}